Fuzz: Consistify usage of alloc/free functions

- Always use tj3Alloc() and tj3Free() for JPEG destination buffers.

- Always use malloc() and free() for other buffers.

Mixing and matching those functions works in the default implementation
of libjpeg-turbo on Un*x platforms, but it isn't guaranteed to work in
all implementations.

Closes #849
This commit is contained in:
DRC
2026-01-09 11:33:43 -05:00
parent 813425f735
commit e9b497016c
12 changed files with 34 additions and 34 deletions

View File

@@ -15,7 +15,7 @@ endif()
project(libjpeg-turbo C) project(libjpeg-turbo C)
set(VERSION 3.1.3) set(VERSION 3.1.3)
set(COPYRIGHT_YEAR "1991-2025") set(COPYRIGHT_YEAR "1991-2026")
string(REPLACE "." ";" VERSION_TRIPLET ${VERSION}) string(REPLACE "." ";" VERSION_TRIPLET ${VERSION})
list(GET VERSION_TRIPLET 0 VERSION_MAJOR) list(GET VERSION_TRIPLET 0 VERSION_MAJOR)
list(GET VERSION_TRIPLET 1 VERSION_MINOR) list(GET VERSION_TRIPLET 1 VERSION_MINOR)

View File

@@ -94,7 +94,7 @@ intended solely for clarification.
The Modified (3-clause) BSD License The Modified (3-clause) BSD License
=================================== ===================================
Copyright (C)2009-2025 D. R. Commander. All Rights Reserved.<br> Copyright (C)2009-2026 D. R. Commander. All Rights Reserved.<br>
Copyright (C)2015 Viktor Szathmáry. All Rights Reserved. Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C)2021, 2023-2025 D. R. Commander. All Rights Reserved. * Copyright (C)2021, 2023-2026 D. R. Commander. All Rights Reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@@ -104,7 +104,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
sum += dstBuf[i]; sum += dstBuf[i];
} }
free(dstBuf); tj3Free(dstBuf);
dstBuf = NULL; dstBuf = NULL;
tj3Free(srcBuf); tj3Free(srcBuf);
srcBuf = NULL; srcBuf = NULL;
@@ -116,7 +116,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
} }
bailout: bailout:
free(dstBuf); tj3Free(dstBuf);
tj3Free(srcBuf); tj3Free(srcBuf);
if (fd >= 0) { if (fd >= 0) {
close(fd); close(fd);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C)2021, 2023-2025 D. R. Commander. All Rights Reserved. * Copyright (C)2021, 2023-2026 D. R. Commander. All Rights Reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@@ -104,7 +104,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
sum += dstBuf[i]; sum += dstBuf[i];
} }
free(dstBuf); tj3Free(dstBuf);
dstBuf = NULL; dstBuf = NULL;
tj3Free(srcBuf); tj3Free(srcBuf);
srcBuf = NULL; srcBuf = NULL;
@@ -116,7 +116,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
} }
bailout: bailout:
free(dstBuf); tj3Free(dstBuf);
tj3Free(srcBuf); tj3Free(srcBuf);
if (fd >= 0) { if (fd >= 0) {
close(fd); close(fd);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C)2021-2025 D. R. Commander. All Rights Reserved. * Copyright (C)2021-2026 D. R. Commander. All Rights Reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@@ -102,7 +102,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
sum += dstBuf[i]; sum += dstBuf[i];
} }
free(dstBuf); tj3Free(dstBuf);
dstBuf = NULL; dstBuf = NULL;
tj3Free(srcBuf); tj3Free(srcBuf);
srcBuf = NULL; srcBuf = NULL;
@@ -114,7 +114,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
} }
bailout: bailout:
free(dstBuf); tj3Free(dstBuf);
tj3Free(srcBuf); tj3Free(srcBuf);
if (fd >= 0) { if (fd >= 0) {
close(fd); close(fd);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C)2021-2025 D. R. Commander. All Rights Reserved. * Copyright (C)2021-2026 D. R. Commander. All Rights Reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@@ -102,7 +102,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
sum += dstBuf[i]; sum += dstBuf[i];
} }
free(dstBuf); tj3Free(dstBuf);
dstBuf = NULL; dstBuf = NULL;
tj3Free(srcBuf); tj3Free(srcBuf);
srcBuf = NULL; srcBuf = NULL;
@@ -114,7 +114,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
} }
bailout: bailout:
free(dstBuf); tj3Free(dstBuf);
tj3Free(srcBuf); tj3Free(srcBuf);
if (fd >= 0) { if (fd >= 0) {
close(fd); close(fd);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C)2021-2025 D. R. Commander. All Rights Reserved. * Copyright (C)2021-2026 D. R. Commander. All Rights Reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@@ -101,7 +101,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
sum += dstBuf[i]; sum += dstBuf[i];
} }
free(dstBuf); tj3Free(dstBuf);
dstBuf = NULL; dstBuf = NULL;
tj3Free(srcBuf); tj3Free(srcBuf);
srcBuf = NULL; srcBuf = NULL;
@@ -113,7 +113,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
} }
bailout: bailout:
free(dstBuf); tj3Free(dstBuf);
tj3Free(srcBuf); tj3Free(srcBuf);
if (fd >= 0) { if (fd >= 0) {
close(fd); close(fd);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C)2021-2025 D. R. Commander. All Rights Reserved. * Copyright (C)2021-2026 D. R. Commander. All Rights Reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@@ -105,8 +105,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
sum += dstBuf[i]; sum += dstBuf[i];
} }
free(dstBuf); tj3Free(dstBuf);
dstBuf = NULL; dstBuf = NULL;
free(yuvBuf); free(yuvBuf);
yuvBuf = NULL; yuvBuf = NULL;
tj3Free(srcBuf); tj3Free(srcBuf);
@@ -119,7 +120,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
} }
bailout: bailout:
free(dstBuf); tj3Free(dstBuf);
free(yuvBuf); free(yuvBuf);
tj3Free(srcBuf); tj3Free(srcBuf);
if (fd >= 0) { if (fd >= 0) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C)2021-2025 D. R. Commander. All Rights Reserved. * Copyright (C)2021-2026 D. R. Commander. All Rights Reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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); tj3SetCroppingRegion(handle, TJUNCROPPED);
} }
if ((dstBuf = tj3Alloc(w * h * tjPixelSize[pf] * sampleSize)) == NULL) if ((dstBuf = malloc(w * h * tjPixelSize[pf] * sampleSize)) == NULL)
goto bailout; goto bailout;
if (precision == 8) { if (precision == 8) {

View File

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

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C)2021-2025 D. R. Commander. All Rights Reserved. * Copyright (C)2021-2026 D. R. Commander. All Rights Reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@@ -90,7 +90,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
goto bailout; goto bailout;
} }
free(dstBufs[0]); tj3Free(dstBufs[0]);
dstBufs[0] = NULL; dstBufs[0] = NULL;
transforms[0].r.w = (height + 1) / 2; transforms[0].r.w = (height + 1) / 2;
@@ -114,7 +114,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
goto bailout; goto bailout;
} }
free(dstBufs[0]); tj3Free(dstBufs[0]);
dstBufs[0] = NULL; dstBufs[0] = NULL;
transforms[0].op = TJXOP_ROT90; transforms[0].op = TJXOP_ROT90;
@@ -135,7 +135,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
goto bailout; goto bailout;
} }
free(dstBufs[0]); tj3Free(dstBufs[0]);
dstBufs[0] = NULL; dstBufs[0] = NULL;
transforms[0].op = TJXOP_NONE; transforms[0].op = TJXOP_NONE;
@@ -155,7 +155,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
} }
bailout: bailout:
free(dstBufs[0]); tj3Free(dstBufs[0]);
tj3Destroy(handle); tj3Destroy(handle);
return 0; return 0;
} }

View File

@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software: * This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding. * Copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding.
* libjpeg-turbo Modifications: * libjpeg-turbo Modifications:
* Copyright (C) 2010, 2012-2025, D. R. Commander. * Copyright (C) 2010, 2012-2026, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -37,7 +37,7 @@
*/ */
#define JCOPYRIGHT1 \ #define JCOPYRIGHT1 \
"Copyright (C) 2009-2025 D. R. Commander\n" \ "Copyright (C) 2009-2026 D. R. Commander\n" \
"Copyright (C) 2015, 2020 Google, Inc.\n" \ "Copyright (C) 2015, 2020 Google, Inc.\n" \
"Copyright (C) 2019-2020 Arm Limited\n" \ "Copyright (C) 2019-2020 Arm Limited\n" \
"Copyright (C) 2015-2016, 2018 Matthieu Darbois\n" \ "Copyright (C) 2015-2016, 2018 Matthieu Darbois\n" \