Giter VIP home page Giter VIP logo

duff's Introduction

Duff โ€“ libXdiff implementation in OCaml

Duff is a little library to implement libXdiff in OCaml. This library is a part of the ocaml-git project. This code is a translation of diff-delta.c available on the git project in OCaml. So, it respects some git's constraints unlike libXdiff.

Examples

This library let the user to calculate an index from a source (a hash-table) which can be computed with a blob. Then, from index (which represents your source) and a blob, we generate a list of Copy and Insert elements.

  • Copy (off, len) means to take a slice of len bytes from your source at off (absolute offset) and copy it.
  • Insert (off, len) means to store a slice of len bytes from your blob at off (absolute offset) and copy it.

From this information, we can have a tiny representation of your blob which can be reconstruct with your source. The goal is to store Copy opcode with off and len, and Insert opcode which contains a slice of your blob.

Finally, to produce a PACK file in git or ocaml-git, we use this algorithm and this representation to optimize storage of your blobs (cf. git gc).

Binary

You can see an example of duff in bin directory. It's an executable to represent a thin representation of your file. Then, you can reconstruct it with patch sub-command.

This is an example to use duff:

$ ./duff.exe diff source target > target.xduff
$ ./duff.exe patch source < target.xduff > target.new
$ diff target target.new
$ echo $?
0

The internal format used is close to what git does internally (without zlib layer). However, it does not correspond to an official format. The binary is not optimized to be used in a production environment but feedback and improvement on it are welcome.

Limitations

Because this project is used by ocaml-git, we have some limitations:

  • We compute at most 0xFFFFFFFE bytes from source
  • An insert block can not be bigger than 0x10000 bytes

For example, libXdiff computes a bigger source than this implementation. Then, limitation about insert block depends on the PACK (git) file format. So, don't ask me to compute bigger source or merge and produce bigger insert block - these constraints is outside the scope of this library.

From this limitation, Copy opcode have an offset between 0x0 and 0xFFFFFFE and off + len is lower than 0xFFFFFFFE.

Fuzzer

We provide a fuzzer to randomly test this library. Currently (4/9/2018), afl-fuzz did not find any bugs and it computed 67.7k cycles (117 paths).

duff's People

Contributors

craigfe avatar dinosaure avatar hannesm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

duff's Issues

fails on 32-bit

#19 381.5 #=== ERROR while compiling duff.0.2 ===========================================#
#19 381.5 # context              2.0.7 | linux/x86_32 | ocaml-base-compiler.4.10.0 | file:///home/opam/opam-repository
#19 381.5 # path                 ~/.opam/4.10/.opam-switch/build/duff.0.2
#19 381.5 # command              ~/.opam/4.10/bin/dune build -p duff -j 71
#19 381.5 # exit-code            1
#19 381.5 # env-file             ~/.opam/log/duff-8-556aff.env
#19 381.5 # output-file          ~/.opam/log/duff-8-556aff.out
#19 381.5 ### output ###
#19 381.5 #       ocamlc lib/.duff.objs/byte/duff.{cmo,cmt} (exit 2)
#19 381.5 # (cd _build/default && /home/opam/.opam/4.10/bin/ocamlc.opt -w -40 -g -bin-annot -I lib/.duff.objs/byte -I /home/opam/.opam/4.10/lib/bigarray-compat -I /home/opam/.opam/4.10/lib/cstruct -I /home/opam/.opam/4.10/lib/fmt -I /home/opam/.opam/4.10/lib/seq -I /home/opam/.opam/4.10/lib/stdlib-shims -intf-suffix .ml -no-alias-deps -o lib/.duff.objs/byte/duff.cmo -c -impl lib/duff.ml)
#19 381.5 # File "lib/duff.ml", line 40, characters 15-25:
#19 381.5 # 40 |           then 2147483647 + (2147483648 + (to_int x))
#19 381.5 #                     ^^^^^^^^^^
#19 381.5 # Error: Integer literal exceeds the range of representable integers of type int
#19 381.5 #     ocamlopt lib/.duff.objs/native/duff.{cmx,o} (exit 2)
#19 381.5 # (cd _build/default && /home/opam/.opam/4.10/bin/ocamlopt.opt -w -40 -g -I lib/.duff.objs/byte -I lib/.duff.objs/native -I /home/opam/.opam/4.10/lib/bigarray-compat -I /home/opam/.opam/4.10/lib/cstruct -I /home/opam/.opam/4.10/lib/fmt -I /home/opam/.opam/4.10/lib/seq -I /home/opam/.opam/4.10/lib/stdlib-shims -intf-suffix .ml -no-alias-deps -o lib/.duff.objs/native/duff.cmx -c -impl lib/duff.ml)
#19 381.5 # File "lib/duff.ml", line 40, characters 15-25:
#19 381.5 # 40 |           then 2147483647 + (2147483648 + (to_int x))
#19 381.5 #                     ^^^^^^^^^^
#19 381.5 # Error: Integer literal exceeds the range of representable integers of type int
#19 381.5 

found via ocurrent/ocaml-ci#219

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.