steveloughran commented on code in PR #3625:
URL: https://github.com/apache/avro/pull/3625#discussion_r3129788869


##########
lang/java/avro/src/main/java/org/apache/avro/file/DeflateCodec.java:
##########
@@ -79,9 +108,30 @@ public ByteBuffer compress(ByteBuffer data) throws 
IOException {
   @Override
   public ByteBuffer decompress(ByteBuffer data) throws IOException {
     NonCopyingByteArrayOutputStream baos = new 
NonCopyingByteArrayOutputStream(DEFAULT_BUFFER_SIZE);
-    try (OutputStream outputStream = new InflaterOutputStream(baos, 
getInflater())) {
-      outputStream.write(data.array(), computeOffset(data), data.remaining());
+    byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
+    long totalBytes = 0;
+
+    Inflater inflater = getInflater();
+    inflater.setInput(data.array(), computeOffset(data), data.remaining());
+
+    try {
+      while (!inflater.finished()) {
+        int len = inflater.inflate(buffer);
+        if (len == 0 && inflater.needsInput()) {
+          break;
+        }
+        totalBytes += len;

Review Comment:
   Better to push the limit logic into NonCopyingByteArrayOutputStream, so all 
decompressors would share the checks; no need to duplicate the overflow logic, 
just instantiate the baos with the (shared) limit value. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to