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

Fix a bug where xlen larger than 0x7fff was rejected #1280

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion okio/src/jvmMain/kotlin/okio/GzipSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class GzipSource(source: Source) : Source {
if (flags.getBit(FEXTRA)) {
source.require(2)
if (fhcrc) updateCrc(source.buffer, 0, 2)
val xlen = source.buffer.readShortLe().toLong()
val xlen = (source.buffer.readShortLe().toInt() and 0xffff).toLong()
source.require(xlen)
if (fhcrc) updateCrc(source.buffer, 0, xlen)
source.skip(xlen)
Expand Down
22 changes: 18 additions & 4 deletions okio/src/jvmTest/kotlin/okio/GzipKotlinTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,28 @@ import org.junit.Test
class GzipKotlinTest {
@Test fun sink() {
val data = Buffer()
val gzip = (data as Sink).gzip()
gzip.buffer().writeUtf8("Hi!").close()
(data as Sink).gzip().buffer().use { gzip ->
gzip.writeUtf8("Hi!")
}
assertEquals("1f8b0800000000000000f3c8540400dac59e7903000000", data.readByteString().hex())
}

@Test fun source() {
val buffer = Buffer().write("1f8b0800000000000000f3c8540400dac59e7903000000".decodeHex())
val gzip = (buffer as Source).gzip()
assertEquals("Hi!", gzip.buffer().readUtf8())
(buffer as Source).gzip().buffer().use { gzip ->
assertEquals("Hi!", gzip.readUtf8())
}
}

@Test fun extraLongXlen() {
val xlen = 0xffff
val buffer = Buffer()
.write("1f8b0804000000000000".decodeHex())
.writeShort(xlen)
.write(ByteArray(xlen))
.write("f3c8540400dac59e7903000000".decodeHex())
(buffer as Source).gzip().buffer().use { gzip ->
assertEquals("Hi!", gzip.readUtf8())
}
}
}