OSS-Fuzz: More MSan fixes

We need to use tj3Alloc() (which, when ZERO_BUFFERS is defined, calls
calloc() instead of malloc()) to allocate all destination buffers.
Otherwise, if the compression/decompression/transform operation fails,
then the buffer checksum (which is computed to prevent the compiler from
optimizing out the whole test, since the destination buffer is never
used otherwise) will depend upon values in the destination buffer that
were never written, and MSan will complain.
This commit is contained in:
DRC 2024-08-19 10:06:59 -04:00
parent 488d42a8a5
commit 562ad7612e
7 changed files with 15 additions and 15 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C)2021-2023 D. R. Commander. All Rights Reserved.
* Copyright (C)2021-2024 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -85,7 +85,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
maxBufSize = tj3JPEGBufSize(width, height, TJSAMP_444);
if (tj3Get(handle, TJPARAM_NOREALLOC)) {
if ((dstBuf = (unsigned char *)malloc(maxBufSize)) == NULL)
if ((dstBuf = (unsigned char *)tj3Alloc(maxBufSize)) == NULL)
goto bailout;
} else
dstBuf = NULL;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C)2021-2023 D. R. Commander. All Rights Reserved.
* Copyright (C)2021-2024 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -85,7 +85,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
maxBufSize = tj3JPEGBufSize(width, height, TJSAMP_444);
if (tj3Get(handle, TJPARAM_NOREALLOC)) {
if ((dstBuf = (unsigned char *)malloc(maxBufSize)) == NULL)
if ((dstBuf = (unsigned char *)tj3Alloc(maxBufSize)) == NULL)
goto bailout;
} else
dstBuf = NULL;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C)2021-2023 D. R. Commander. All Rights Reserved.
* Copyright (C)2021-2024 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -84,7 +84,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
maxBufSize = tj3JPEGBufSize(width, height, TJSAMP_444);
if (tj3Get(handle, TJPARAM_NOREALLOC)) {
if ((dstBuf = (unsigned char *)malloc(maxBufSize)) == NULL)
if ((dstBuf = (unsigned char *)tj3Alloc(maxBufSize)) == NULL)
goto bailout;
} else
dstBuf = NULL;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C)2021-2023 D. R. Commander. All Rights Reserved.
* Copyright (C)2021-2024 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -87,7 +87,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
continue;
maxBufSize = tj3JPEGBufSize(width, height, tests[ti].subsamp);
if ((dstBuf = (unsigned char *)malloc(maxBufSize)) == NULL)
if ((dstBuf = (unsigned char *)tj3Alloc(maxBufSize)) == NULL)
goto bailout;
if ((yuvBuf =
(unsigned char *)malloc(tj3YUVBufSize(width, 1, height,

View File

@ -1,5 +1,5 @@
/*
* Copyright (C)2021-2023 D. R. Commander. All Rights Reserved.
* Copyright (C)2021-2024 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -95,7 +95,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
tj3SetCroppingRegion(handle, TJUNCROPPED);
}
if ((dstBuf = malloc(w * h * tjPixelSize[pf] * sampleSize)) == NULL)
if ((dstBuf = tj3Alloc(w * h * tjPixelSize[pf] * sampleSize)) == NULL)
goto bailout;
if (precision == 8) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (C)2021-2023 D. R. Commander. All Rights Reserved.
* Copyright (C)2021-2024 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -83,7 +83,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
tj3SetScalingFactor(handle, TJUNSCALED);
}
if ((dstBuf = (unsigned char *)malloc(w * h * tjPixelSize[pf])) == NULL)
if ((dstBuf = (unsigned char *)tj3Alloc(w * h * tjPixelSize[pf])) == NULL)
goto bailout;
if ((yuvBuf =
(unsigned char *)malloc(tj3YUVBufSize(w, 1, h, jpegSubsamp))) == NULL)

View File

@ -101,8 +101,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
transforms[0].options = TJXOPT_GRAY | TJXOPT_CROP | TJXOPT_COPYNONE |
TJXOPT_OPTIMIZE;
dstBufs[0] =
(unsigned char *)malloc(tj3JPEGBufSize((height + 1) / 2, (width + 1) / 2,
jpegSubsamp));
(unsigned char *)tj3Alloc(tj3JPEGBufSize((height + 1) / 2, (width + 1) / 2,
jpegSubsamp));
if (!dstBufs[0])
goto bailout;
@ -125,7 +125,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
transforms[0].op = TJXOP_ROT90;
transforms[0].options = TJXOPT_TRIM | TJXOPT_ARITHMETIC;
dstBufs[0] =
(unsigned char *)malloc(tj3JPEGBufSize(height, width, jpegSubsamp));
(unsigned char *)tj3Alloc(tj3JPEGBufSize(height, width, jpegSubsamp));
if (!dstBufs[0])
goto bailout;