iemejia commented on code in PR #3854:
URL: https://github.com/apache/avro/pull/3854#discussion_r3568074786


##########
lang/c++/impl/ZstdDecompressWrapper.cc:
##########
@@ -43,9 +43,21 @@ std::string ZstdDecompressWrapper::decompress(const 
std::vector<char> &compresse
             if (ZSTD_isError(ret)) {
                 throw Exception("ZSTD decompression error: {}", 
ZSTD_getErrorName(ret));
             }
+            // Reject before appending so the buffer never grows past the 
limit.
+            if (out.pos > maxLength - uncompressed.size()) {
+                throw Exception(
+                    "Decompressed block size {} exceeds the maximum allowed of 
{} bytes",
+                    uncompressed.size() + out.pos, maxLength);
+            }

Review Comment:
   Fixed — the zstd message uses a saturating add for uncompressed.size() + 
out.pos.



##########
lang/c++/impl/DataFile.cc:
##########
@@ -627,12 +679,30 @@ void DataFileReaderBase::readDataBlock() {
 
             const uint8_t *data;
             size_t len;
+            const size_t maxLength = maxDecompressLength();

Review Comment:
   Already handled — maxLength is clamped to std::numeric_limits<uLong>::max() 
before the loop so z_stream::total_out (a uLong) can't overflow; the buffer 
arithmetic uses total_out safely.



-- 
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