Skip to content

Commit 9ed2595

Browse files
Clear the deflater's byte array reference (#1612)
Even though the content of this array isn't read, it looks like deflater may still interfere by making a pair of calls to GetPrimitiveArrayCritical + ReleasePrimitiveArrayCritical. Closes: #1608 Co-authored-by: Jesse Wilson <[email protected]>
1 parent 7f14587 commit 9ed2595

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

okio/src/jvmMain/kotlin/okio/DeflaterSink.kt

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package okio
1919

2020
import java.util.zip.Deflater
21+
import okio.internal.EMPTY_BYTE_ARRAY
2122

2223
actual class DeflaterSink internal actual constructor(
2324
private val sink: BufferedSink,
@@ -51,6 +52,10 @@ actual class DeflaterSink internal actual constructor(
5152

5253
remaining -= toDeflate
5354
}
55+
56+
// Deflater still holds a reference to the most recent segment's byte array. That can cause
57+
// problems in JNI, so clear it now. https://github.com/square/okio/issues/1608
58+
deflater.setInput(EMPTY_BYTE_ARRAY, 0, 0)
5459
}
5560

5661
private fun deflate(syncFlush: Boolean) {

okio/src/jvmMain/kotlin/okio/internal/-ZlibJvm.kt

+2
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ internal actual fun datePartsToEpochMillis(
3636
calendar.set(year, month - 1, day, hour, minute, second)
3737
return calendar.time.time
3838
}
39+
40+
internal val EMPTY_BYTE_ARRAY = byteArrayOf()

0 commit comments

Comments
 (0)