File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -117,7 +117,7 @@ class GzipSource(source: Source) : Source {
117117 if (flags.getBit(FEXTRA )) {
118118 source.require(2 )
119119 if (fhcrc) updateCrc(source.buffer, 0 , 2 )
120- val xlen = source.buffer.readShortLe().toLong()
120+ val xlen = ( source.buffer.readShortLe().toInt() and 0xffff ).toLong()
121121 source.require(xlen)
122122 if (fhcrc) updateCrc(source.buffer, 0 , xlen)
123123 source.skip(xlen)
Original file line number Diff line number Diff line change @@ -23,14 +23,28 @@ import org.junit.Test
2323class GzipKotlinTest {
2424 @Test fun sink () {
2525 val data = Buffer ()
26- val gzip = (data as Sink ).gzip()
27- gzip.buffer().writeUtf8(" Hi!" ).close()
26+ (data as Sink ).gzip().buffer().use { gzip ->
27+ gzip.writeUtf8(" Hi!" )
28+ }
2829 assertEquals(" 1f8b0800000000000000f3c8540400dac59e7903000000" , data.readByteString().hex())
2930 }
3031
3132 @Test fun source () {
3233 val buffer = Buffer ().write(" 1f8b0800000000000000f3c8540400dac59e7903000000" .decodeHex())
33- val gzip = (buffer as Source ).gzip()
34- assertEquals(" Hi!" , gzip.buffer().readUtf8())
34+ (buffer as Source ).gzip().buffer().use { gzip ->
35+ assertEquals(" Hi!" , gzip.readUtf8())
36+ }
37+ }
38+
39+ @Test fun extraLongXlen () {
40+ val xlen = 0xffff
41+ val buffer = Buffer ()
42+ .write(" 1f8b0804000000000000" .decodeHex())
43+ .writeShort(xlen)
44+ .write(ByteArray (xlen))
45+ .write(" f3c8540400dac59e7903000000" .decodeHex())
46+ (buffer as Source ).gzip().buffer().use { gzip ->
47+ assertEquals(" Hi!" , gzip.readUtf8())
48+ }
3549 }
3650}
You can’t perform that action at this time.
0 commit comments