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)
set(VERSION 3.1.3)
set(COPYRIGHT_YEAR "1991-2025")
set(COPYRIGHT_YEAR "1991-2026")
string(REPLACE "." ";" VERSION_TRIPLET ${VERSION})
list(GET VERSION_TRIPLET 0 VERSION_MAJOR)
list(GET VERSION_TRIPLET 1 VERSION_MINOR)

View File

@@ -94,7 +94,7 @@ intended solely for clarification.
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.
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
* 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];
}
free(dstBuf);
tj3Free(dstBuf);
dstBuf = NULL;
tj3Free(srcBuf);
srcBuf = NULL;
@@ -116,7 +116,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
}
bailout:
free(dstBuf);
tj3Free(dstBuf);
tj3Free(srcBuf);
if (fd >= 0) {
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
* 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];
}
free(dstBuf);
tj3Free(dstBuf);
dstBuf = NULL;
tj3Free(srcBuf);
srcBuf = NULL;
@@ -116,7 +116,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
}
bailout:
free(dstBuf);
tj3Free(dstBuf);
tj3Free(srcBuf);
if (fd >= 0) {
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
* 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];
}
free(dstBuf);
tj3Free(dstBuf);
dstBuf = NULL;
tj3Free(srcBuf);
srcBuf = NULL;
@@ -114,7 +114,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
}
bailout:
free(dstBuf);
tj3Free(dstBuf);
tj3Free(srcBuf);
if (fd >= 0) {
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
* 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];
}
free(dstBuf);
tj3Free(dstBuf);
dstBuf = NULL;
tj3Free(srcBuf);
srcBuf = NULL;
@@ -114,7 +114,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
}
bailout:
free(dstBuf);
tj3Free(dstBuf);
tj3Free(srcBuf);
if (fd >= 0) {
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
* 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];
}
free(dstBuf);
tj3Free(dstBuf);
dstBuf = NULL;
tj3Free(srcBuf);
srcBuf = NULL;
@@ -113,7 +113,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
}
bailout:
free(dstBuf);
tj3Free(dstBuf);
tj3Free(srcBuf);
if (fd >= 0) {
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
* 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];
}
free(dstBuf);
tj3Free(dstBuf);
dstBuf = NULL;
free(yuvBuf);
yuvBuf = NULL;
tj3Free(srcBuf);
@@ -119,7 +120,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
}
bailout:
free(dstBuf);
tj3Free(dstBuf);
free(yuvBuf);
tj3Free(srcBuf);
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
* 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 = tj3Alloc(w * h * tjPixelSize[pf] * sampleSize)) == NULL)
if ((dstBuf = malloc(w * h * tjPixelSize[pf] * sampleSize)) == NULL)
goto bailout;
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
* 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);
}
if ((dstBuf = (unsigned char *)tj3Alloc(w * h * tjPixelSize[pf])) == NULL)
if ((dstBuf = (unsigned char *)malloc(w * h * tjPixelSize[pf])) == NULL)
goto bailout;
if ((yuvBuf =
(unsigned char *)tj3Alloc(tj3YUVBufSize(w, 1, h,
jpegSubsamp))) == NULL)
if ((yuvBuf = (unsigned char *)malloc(tj3YUVBufSize(w, 1, h,
jpegSubsamp))) == NULL)
goto bailout;
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
* 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;
}
free(dstBufs[0]);
tj3Free(dstBufs[0]);
dstBufs[0] = NULL;
transforms[0].r.w = (height + 1) / 2;
@@ -114,7 +114,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
goto bailout;
}
free(dstBufs[0]);
tj3Free(dstBufs[0]);
dstBufs[0] = NULL;
transforms[0].op = TJXOP_ROT90;
@@ -135,7 +135,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
goto bailout;
}
free(dstBufs[0]);
tj3Free(dstBufs[0]);
dstBufs[0] = NULL;
transforms[0].op = TJXOP_NONE;
@@ -155,7 +155,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
}
bailout:
free(dstBufs[0]);
tj3Free(dstBufs[0]);
tj3Destroy(handle);
return 0;
}

View File

@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding.
* 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
* file.
*
@@ -37,7 +37,7 @@
*/
#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) 2019-2020 Arm Limited\n" \
"Copyright (C) 2015-2016, 2018 Matthieu Darbois\n" \