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

Xgit.Util.UnzipStream: No code coverage for zlib :continue case #50

Closed
scouten opened this issue Aug 5, 2019 · 4 comments
Closed

Xgit.Util.UnzipStream: No code coverage for zlib :continue case #50

scouten opened this issue Aug 5, 2019 · 4 comments
Labels

Comments

@scouten
Copy link
Collaborator

@scouten scouten commented Aug 5, 2019

  • Add label: "bug"
  • Add label: "good first issue" or "help wanted" if appropriate

Describe the Bug
In Xgit.Util.UnzipStream.process_all_data/3 the case where :zlib.safeInflate/2 returns {:continue, data} is not reachable by any test data I've been able to construct.

Steps to Reproduce
If I knew … 😉

@scouten scouten mentioned this issue Aug 5, 2019
4 of 6 tasks complete
@dbernheisel

This comment has been minimized.

Copy link

@dbernheisel dbernheisel commented Aug 18, 2019

Haven't tested yet myself, but I think if you take the compressed binary, and splitt it into 2 parts and only throw the 1st part into :zlib.safeInflate/2 you should get the :continue response. This may also show itself if the file is larger than the initial-read buffer.

Here's an example:

# generate a random large file
$ dd if=/dev/urandom of=largefile.txt bs=1048576 count=10
$ gzip largefile.txt
# => largefile.txt.gz
defmodule Test do
  @windowbits 15 + 32 # automatically detect headers and deflate
  @stream_bytes 50
  def decompress(file) do
    z = :zlib.open()
    :zlib.inflateInit(z, @windowbits)
    binary = file |> File.stream!([], @stream_bytes) |> Enum.take(1000)
    loop(z, :zlib.safeInflate(z, binary))
  end
  
  def loop(z, {:continue, _incomplete_decompressed_binary}) do
    # wait in a holding pattern until we get more binary
    IO.puts "waiting for more data"
    loop(z, :zlib.safeInflate(z, []))
  end
  
  def loop(z, {:finished, decompressed_data}) do
    IO.puts "done"
    :zlib.close(z)
    decompressed_data
  end
end

Test.decompress("largefile.txt.gz")
#=> waiting for more data
#=> waiting for more data
#=> waiting for more data
#=> done
#=> [
  <<150, 228, 216, 236, 53, 47, 20, 62, 248, 185, 65, 227, 173, 63, 163, 31,
    248, 207, 252, 79, 134, 34, 193, 185, 23, 122, 23, 62, 250, 7, 241, 229,
    126, 251, 192, 135, 139, 173, 68, 132, 79, 67, 7, 250, 100, 252, 167, 228,
    245, ...>>
]

This may be a good place to start for understanding how to write a test to cover :continue

@scouten

This comment has been minimized.

Copy link
Collaborator Author

@scouten scouten commented Aug 19, 2019

@dbernheisel thank you, that looks like a promising lead!

scouten added a commit that referenced this issue Aug 19, 2019
Closes #50. Thank you to @dbernheisel for the idea for how to accomplish this.
@scouten

This comment has been minimized.

Copy link
Collaborator Author

@scouten scouten commented Aug 19, 2019

Confirmed. Fix coming soon. Thank you!

scouten added a commit that referenced this issue Aug 19, 2019
Closes #50. Thank you to @dbernheisel for the idea for how to accomplish this.
@scouten

This comment has been minimized.

Copy link
Collaborator Author

@scouten scouten commented Aug 19, 2019

Closed by #104. Will be included in a new release soon.

@scouten scouten closed this Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.