Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid_crc on a git blob. #6

Closed
mmaker opened this issue Mar 13, 2016 · 4 comments
Closed

Invalid_crc on a git blob. #6

mmaker opened this issue Mar 13, 2016 · 4 comments

Comments

@mmaker
Copy link

mmaker commented Mar 13, 2016

With the following git pack:
http://tumbolandia.net/pack.dump

I get Exception: Decompress_inflate.Make(X).Invalid_crc., even though this seems to be perfectly fine for Zlib.

I used @yomimono's interface of Inflator available here: https://github.com/Engil/Canopy/blob/master/inflator.ml, and down here you can find a session of utop that reproduces the error.

───────────────────────────────────────────────────────────────────────────────────────┬──────────────────────────────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────────────
                                                                                       │ Welcome to utop version 1.18.2 (using OCaml version 4.02.3)! │
                                                                                       └──────────────────────────────────────────────────────────────┘

Type #utop_help for help about using utop.

─( 19:18:02 )─< command 0 >─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # #require "irmin";;
─( 19:18:02 )─< command 1 >─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # #require "decompress";;
─( 19:18:11 )─< command 2 >─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # #require "git.unix";;
─( 19:18:17 )─< command 3 >─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # let load_file f =
  let ic = open_in f in
  let n = in_channel_length ic in
  let s = Bytes.create n in
  really_input ic s 0 n;
  close_in ic;
  (s);;
val load_file : bytes -> bytes = <fun>
─( 19:18:22 )─< command 4 >─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # let m =
     let b = load_file "/tmp/pack.dump" in
     Mstruct.of_string b;;
val m : Mstruct.t = <abstr>
─( 19:18:30 )─< command 5 >─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # #mod_use "Canopy/inflator.ml";;
module Inflator :
  sig
    module IDBytes :
      sig
        external length : bytes -> int = "%string_length"
        external get : bytes -> int -> char = "%string_safe_get"
        external set : bytes -> int -> char -> unit = "%string_safe_set"
        external create : int -> bytes = "caml_create_string"
        val make : int -> char -> bytes
        val init : int -> (int -> char) -> bytes
        val empty : bytes
        val copy : bytes -> bytes
        val of_string : bytes -> bytes
        val to_string : bytes -> bytes
        val sub : bytes -> int -> int -> bytes
        val sub_string : bytes -> int -> int -> bytes
        val extend : bytes -> int -> int -> bytes
        val fill : bytes -> int -> int -> char -> unit
        val blit : bytes -> int -> bytes -> int -> int -> unit
        val blit_string : bytes -> int -> bytes -> int -> int -> unit
        val cat : bytes -> bytes -> bytes
        val iter : (char -> unit) -> bytes -> unit
        val iteri : (int -> char -> unit) -> bytes -> unit
        val map : (char -> char) -> bytes -> bytes
        val mapi : (int -> char -> char) -> bytes -> bytes
        val trim : bytes -> bytes
        val escaped : bytes -> bytes
        val index : bytes -> char -> int
        val rindex : bytes -> char -> int
        val index_from : bytes -> int -> char -> int
        val rindex_from : bytes -> int -> char -> int
        val contains : bytes -> char -> bool
        val contains_from : bytes -> int -> char -> bool
        val rcontains_from : bytes -> int -> char -> bool
        val uppercase : bytes -> bytes
        val lowercase : bytes -> bytes
        val capitalize : bytes -> bytes
        val uncapitalize : bytes -> bytes
        type t = bytes
        val compare : t -> t -> int
        val unsafe_to_string : t -> t
        val unsafe_of_string : t -> t
        external unsafe_get : t -> int -> char = "%string_unsafe_get"
        external unsafe_set : t -> int -> char -> unit = "%string_unsafe_set"
        external unsafe_blit : t -> int -> t -> int -> int -> unit = "caml_blit_string" "noalloc"
        external unsafe_fill : t -> int -> int -> char -> unit = "caml_fill_string" "noalloc"
        val concat : t -> t list -> t
        val of_bytes : 'a -> 'a
        val to_bytes : 'a -> 'a
      end
    module XInflator :
      sig
        type t = Decompress_inflate.Make(IDBytes).t
        type src = [ `Channel of in_channel | `Manual of int -> bytes | `String of int * bytes ]
        type dst = bytes
        val make : [< src ] -> dst -> t
        val eval : t -> [ `Error | `Flush of int | `Ok of int ]
        val contents : t -> int
        val flush : t -> unit
      end
    module XDeflator :
      sig
        type t = Decompress_deflate.Make(IDBytes).t
        type src = [ `Channel of in_channel | `Manual of unit -> bytes * bool | `String of int * bytes ]
        type dst = bytes
        val make : ?window_bits:int -> [< src ] -> dst -> t
        val eval : t -> [ `Error | `Flush | `Ok ]
        val contents : t -> int
        val flush : t -> unit
      end
    val inflate : ?output_size:int -> Mstruct.t -> Mstruct.t option
    val deflate : ?level:'a -> Cstruct.t -> Cstruct.t
  end
─( 19:18:33 )─< command 6 >─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # Inflator.inflate (Mstruct.clone m);;
output_size: 0 wrote 416217 of 416217
Exception: Decompress_inflate.Make(X).Invalid_crc.
─( 19:18:46 )─< command 7 >─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # Git_unix.Zlib.inflate (Mstruct.clone m);;
- : Mstruct.t option = Some <abstr>```
@mmaker
Copy link
Author

mmaker commented Mar 13, 2016

I don't really know where to go from here.
Doing some additional tests I found out that this happens only if the git pack I download contains in the git log a jpeg image (for example, pdf files are okay).
Is there anything else I can do to trace down the problem?

@dinosaure
Copy link
Member

Ok, thank you for your issue and your explaination ! I will push lot of feature soon (for example, a PPX to trace the compute of inflate/deflate with no overhead, and I think this feature will catch the error more precisely).

I add this bug in my TODO list !

@mmaker
Copy link
Author

mmaker commented Mar 19, 2016

Thanks!

@dinosaure
Copy link
Member

Hello,

After a large change in Decompress on debug/level/optimization/cookies/whatever, I tried to test your pack.dump. Firstly, I love your image (definitely the best issue). Secondly, I fixed lot of bug independently than your issue and after this change, Decompress can inflate your pack.dump (so I did something in the code but I don't know what).

So, I will do a new release (0.4) but it's yet an experimental implementation of zlib and, I think, we need more use-cases (cc @engil) to prove the non-failed of Decompress.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants