Skip to content

Commit 93ed992

Browse files
garydgregoryluben
authored andcommitted
Fix segmentation fault when calling Zstd.loadDictDecompress(...)
1 parent b97eed7 commit 93ed992

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/main/native/jni_zstd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ JNIEXPORT jlong JNICALL Java_com_github_luben_zstd_Zstd_getErrorCode
237237
*/
238238
JNIEXPORT jint JNICALL Java_com_github_luben_zstd_Zstd_loadDictDecompress
239239
(JNIEnv *env, jclass obj, jlong stream, jbyteArray dict, jint dict_size) {
240+
if (dict == NULL) return -ZSTD_error_dictionary_wrong;
240241
size_t size = -ZSTD_error_memory_allocation;
241242
void *dict_buff = (*env)->GetPrimitiveArrayCritical(env, dict, NULL);
242243
if (dict_buff == NULL) goto E1;

src/test/scala/Zstd.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,13 @@ class ZstdSpec extends AnyFlatSpec with ScalaCheckPropertyChecks {
937937
assert(Zstd.loadFastDictDecompress(0, null.asInstanceOf[ZstdDictDecompress]) == -32)
938938
}
939939

940+
"Zstd" should s"do not cause a segmentation fault in loadDictDecompress()" in {
941+
// Avoid:
942+
// 0 0x000000010185e7c8 AccessInternal::PostRuntimeDispatch<G1BarrierSet::AccessBarrier<548964ull, G1BarrierSet>, (AccessInternal::BarrierType)2, 548964ull>::oop_access_barrier(void*) + 8 in libjvm.dylib
943+
// 1 0x0000000101c17ca8 jni_GetPrimitiveArrayCritical + 340 in libjvm.dylib
944+
assert(Zstd.loadDictDecompress(0, null , 0) == -32)
945+
}
946+
940947
"ZstdDirectBufferCompressingStream" should s"do nothing on double close but throw on writing on closed stream" in {
941948
val os = ByteBuffer.allocateDirect(100)
942949
val zos = new ZstdDirectBufferCompressingStream(os, 1)

0 commit comments

Comments
 (0)