Skip to content
This repository has been archived by the owner. It is now read-only.

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

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

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

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

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 added bug help wanted labels Aug 5, 2019
@dbernheisel
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
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
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
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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug help wanted
Projects
None yet
Development

No branches or pull requests

2 participants