Skip to content

Commit

Permalink
[core/zip] Validate target size before compression
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hahnjo committed Feb 8, 2024
1 parent 17e3561 commit 23261a6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/zip/src/RZip.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,18 @@ unsigned long R__crc32(unsigned long crc, const unsigned char* buf, unsigned int
/* 3 = old */
void R__zipMultipleAlgorithm(int cxlevel, int *srcsize, char *src, int *tgtsize, char *tgt, int *irep, ROOT::RCompressionSetting::EAlgorithm::EValues compressionAlgorithm)
{
*irep = 0;

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

if (cxlevel <= 0) {
*irep = 0;
return;
}

Expand Down

0 comments on commit 23261a6

Please sign in to comment.