Skip to content

Commit 23261a6

Browse files
committed
[core/zip] Validate target size before compression
In practice, the target size is greater or equal the source size in most cases for ROOT, but add this additional correct check to fuzz the inputs in the next commit.
1 parent 17e3561 commit 23261a6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

core/zip/src/RZip.cxx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,18 @@ unsigned long R__crc32(unsigned long crc, const unsigned char* buf, unsigned int
7878
/* 3 = old */
7979
void R__zipMultipleAlgorithm(int cxlevel, int *srcsize, char *src, int *tgtsize, char *tgt, int *irep, ROOT::RCompressionSetting::EAlgorithm::EValues compressionAlgorithm)
8080
{
81+
*irep = 0;
8182

83+
// Performance optimization: avoid compressing tiny source buffers.
8284
if (*srcsize < 1 + HDRSIZE + 1) {
83-
*irep = 0;
85+
return;
86+
}
87+
// Correctness check: we need at least enough bytes to prepend the header!
88+
if (*tgtsize <= HDRSIZE) {
8489
return;
8590
}
8691

8792
if (cxlevel <= 0) {
88-
*irep = 0;
8993
return;
9094
}
9195

0 commit comments

Comments
 (0)