import from UXP: [XPCOM] Add more validation to SnappyUncompressInputStream (d323fc30)

This commit is contained in:
2026-04-02 23:57:03 +08:00
parent ae3b17332e
commit c0b6402640
+4 -1
View File
@@ -23,7 +23,7 @@ static size_t CompressedBufferLength()
static size_t kCompressedBufferLength =
detail::SnappyFrameUtils::MaxCompressedBufferLength(snappy::kBlockSize);
MOZ_ASSERT(kCompressedBufferLength > 0);
MOZ_ASSERT(kCompressedBufferLength > detail::SnappyFrameUtils::kHeaderLength);
return kCompressedBufferLength;
}
@@ -270,6 +270,9 @@ SnappyUncompressInputStream::ParseNextChunk(uint32_t* aBytesReadOut)
// Read at least that much from the base stream.
uint32_t readLength = mNextChunkDataLength;
MOZ_ASSERT(readLength <= CompressedBufferLength());
if (readLength > CompressedBufferLength() - kHeaderLength) {
return NS_ERROR_CORRUPTED_CONTENT;
}
// However, if there is enough data in the base stream, also read the next
// chunk header. This helps optimize the stream by avoiding many small reads.