Skip to content

Commit 9f7553b

Browse files
sjung-stripejojochuang
authored andcommitted
HADOOP-17096. Fix ZStandardCompressor input buffer offset (#2104). Contributed by Stephen Jung (Stripe).
(cherry picked from commit 45434c9) (cherry picked from commit 0712505)
1 parent e2d7e72 commit 9f7553b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/zstd/ZStandardCompressor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public boolean needsInput() {
159159
}
160160

161161
// have we consumed all input
162-
if (keepUncompressedBuf && uncompressedDirectBufLen > 0) {
162+
if (keepUncompressedBuf && uncompressedDirectBufLen - uncompressedDirectBufOff > 0) {
163163
return false;
164164
}
165165

@@ -223,7 +223,7 @@ public int compress(byte[] b, int off, int len) throws IOException {
223223
compressedDirectBuf.limit(n);
224224

225225
// Check if we have consumed all input buffer
226-
if (uncompressedDirectBufLen <= 0) {
226+
if (uncompressedDirectBufLen - uncompressedDirectBufOff <= 0) {
227227
// consumed all input buffer
228228
keepUncompressedBuf = false;
229229
uncompressedDirectBuf.clear();

hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/compress/zstd/ZStandardCompressor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,13 @@ JNIEXPORT jint Java_org_apache_hadoop_io_compress_zstd_ZStandardCompressor_defla
219219
return (jint) 0;
220220
}
221221

222-
bytes_read += input.pos;
222+
bytes_read += input.pos - uncompressed_direct_buf_off;
223223
bytes_written += output.pos;
224224
(*env)->SetLongField(env, this, ZStandardCompressor_bytesRead, bytes_read);
225225
(*env)->SetLongField(env, this, ZStandardCompressor_bytesWritten, bytes_written);
226226

227227
(*env)->SetIntField(env, this, ZStandardCompressor_uncompressedDirectBufOff, input.pos);
228-
(*env)->SetIntField(env, this, ZStandardCompressor_uncompressedDirectBufLen, input.size - input.pos);
228+
(*env)->SetIntField(env, this, ZStandardCompressor_uncompressedDirectBufLen, input.size);
229229
return (jint) output.pos;
230230
}
231231

0 commit comments

Comments
 (0)