Skip to content

Commit

Permalink
Inflater with DEF_WBITS+32 should accept zlib and gzip data.
Browse files Browse the repository at this point in the history
  • Loading branch information
ymnk committed Feb 20, 2013
1 parent 555ca75 commit 389af32
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/jcraft/jzlib/Inflate.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ else if((w&INFLATE_ANY) != 0){
if(w < 48)
w &= 15;
}
else if((w & ~31) != 0) { // for example, DEF_WBITS + 32
wrap = 4; // zlib and gzip wrapped data should be accepted.
w &= 15;
}
else {
wrap = (w >> 4) + 1;
if(w < 48)
Expand Down
54 changes: 54 additions & 0 deletions src/test/scala/WrapperTypeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,60 @@ class WrapperTypeTest {
}
}

@Test
def wbits_plus_32 = {

var deflater = new Deflater
err = deflater.init(Z_BEST_SPEED, DEF_WBITS, 9)
assertThat(err, is(Z_OK))

deflate(deflater, data, compr)

var inflater = new Inflater
err = inflater.init(DEF_WBITS + 32)
assertThat(err, is(Z_OK))

inflater.setInput(compr)

var loop = true
while(loop) {
inflater.setOutput(uncompr)
err = inflater.inflate(Z_NO_FLUSH)
if(err == Z_STREAM_END) loop = false
else assertThat(err, is(Z_OK))
}
err = inflater.end
assertThat(err, is(Z_OK))

var total_out = inflater.total_out.asInstanceOf[Int]
assertThat(new String(uncompr, 0, total_out), is(new String(data)))

deflater = new Deflater
err = deflater.init(Z_BEST_SPEED, DEF_WBITS + 16, 9)
assertThat(err, is(Z_OK))

deflate(deflater, data, compr)

inflater = new Inflater
err = inflater.init(DEF_WBITS + 32)
assertThat(err, is(Z_OK))

inflater.setInput(compr)

loop = true
while(loop) {
inflater.setOutput(uncompr)
err = inflater.inflate(Z_NO_FLUSH)
if(err == Z_STREAM_END) loop = false
else assertThat(err, is(Z_OK))
}
err = inflater.end
assertThat(err, is(Z_OK))

total_out = inflater.total_out.asInstanceOf[Int]
assertThat(new String(uncompr, 0, total_out), is(new String(data)))
}

private def deflate(deflater: ZStream,
data: Array[Byte], compr: Array[Byte]) = {
deflater.setInput(data)
Expand Down

0 comments on commit 389af32

Please sign in to comment.