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

zlib failure in utop #7

Closed
hcarty opened this issue Jan 23, 2018 · 13 comments
Closed

zlib failure in utop #7

hcarty opened this issue Jan 23, 2018 · 13 comments

Comments

@hcarty
Copy link

hcarty commented Jan 23, 2018

Example from a fresh utop/toplevel session using cryptokit 1.12 from opam on a 64bit Linux VM:

let c = Cryptokit.Zlib.compress ();;
let s' = Cryptokit.transform_string c "x";;

The last line raises:

Exception: Cryptokit.Error (Cryptokit.Compression_error ("Zlib.deflate", "")).

The same exception is raised when compiling with ocamlopt.

The following works, however:

let s' = Cryptokit.transform_string (Cryptokit.Zlib.compress ()) (String.make 1 'x');;
@xavierleroy
Copy link
Owner

I haven't been able to reproduce the issue so far. This is what I'm doing (with OCaml 4.06.0 on Ubuntu 16.04 x86-64):

$ cat bug.ml
let c = Cryptokit.Zlib.compress ();;
let s' = Cryptokit.transform_string c "x";;
let _ = print_endline (String.escaped s');;
$ ocamlfind ocamlopt -linkpkg -package cryptokit bug.ml
$ ./a.out
\171\000\000

No Cryptokit.Error exception.

Is there any way you could narrow down the issue? Because I can't.

@hcarty
Copy link
Author

hcarty commented Feb 12, 2018

I can't reproduce the failure I was getting when compiling with ocamlopt.

I can reproduce the failure under utop but not with vanilla ocaml.

For utop:

utop -init /dev/null

#require "cryptokit";;
let c = Cryptokit.Zlib.compress ();;
let s' = Cryptokit.transform_string c "x";;
(* Exception: Cryptokit.Error (Cryptokit.Compression_error ("Zlib.deflate", "")). *)

For ocaml:

ocaml

#use "topfind";;
#require "cryptokit";;
let c = Cryptokit.Zlib.compress ();;
let s' = Cryptokit.transform_string c "x";;
(* val s' : string = "?\000\000" *)

@hcarty
Copy link
Author

hcarty commented Feb 13, 2018

I think this is the failure I saw previously under ocamlopt, though I don't know if it's related to the failure under utop:

let () =
  ignore
    (Cryptokit.transform_string
       (Cryptokit.Zlib.uncompress ())
       (Cryptokit.transform_string
          (Cryptokit.Zlib.compress ())
          (String.make 10_000_000 'x')))

dies with Fatal error: exception Cryptokit.Error(_)

@UnixJunkie
Copy link
Contributor

I also see a problem with compress.
Though the cryptokit in opam is lagging one version behind the released one (I sent a PR in opam-repository to try to fix that).
I will report if I manage to pinpoint better the Zlib compress problem.
It happens in utop and in compiled programs too.

@UnixJunkie
Copy link
Contributor

zlib1g:amd64 1:1.2.11.dfsg-0ubuntu2
zlib1g-dev:amd64 1:1.2.11.dfsg-0ubuntu2

@UnixJunkie
Copy link
Contributor

The following crashes at a random point in both utop and \ocaml:

#use "topfind";;
#require "cryptokit";;

let compress str =
  let gzip = Cryptokit.Zlib.compress ~level:1 () in
  gzip#put_string str;
  gzip#flush;
  gzip#get_string

let () =
  for i = 1 to 1_000_000 do
    Printf.printf "%d\n%!" i;
    ignore (compress (string_of_int i))
  done

Does someone else also see this crashing?

@UnixJunkie
Copy link
Contributor

changing the compression level doesn't make the problem go away

@UnixJunkie
Copy link
Contributor

Fatal error: exception Cryptokit.Error(_)
Raised by primitive operation at file "src/cryptokit.ml", line 1907, characters 10-134

@UnixJunkie
Copy link
Contributor

I wanted to do this:

module M = struct
  let gzip = Cryptokit.Zlib.compress ~level:1 ()
  let compress str =
    gzip#put_string str;
    gzip#flush;
    gzip#get_string
end

Because this is not for crypto.
I don't want to wipe the transform and have to recreate one every time.

@UnixJunkie
Copy link
Contributor

@hcarty can you reliably reproduce the problem with the script I sent?
I'm using 4.06.1 but not sure if it matters.

@hcarty
Copy link
Author

hcarty commented Jun 21, 2018

@UnixJunkie I get failure from the code in #7 (comment) as well under 4.06.0

@mfp
Copy link
Contributor

mfp commented Aug 28, 2019

#16 is a very likely culprit for this.

@UnixJunkie
Copy link
Contributor

I think this can be closed based on the recent PR that was merged.
Maybe a test is in order though.

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

4 participants