Skip to content

Commit 3b9e867

Browse files
committed
Don't store a value read directly from the bitstream in an enum
In this case, the enum only has one single allowed value, while the bitstream can contain a number of different values. Don't load the unchecked value into an enum variable, because storing the disallowed values in the enum variable is undefined behaviour. Instead store it in an int, until the value has been verified to be the allowed one. This fixes undefined behaviour sanitizer errors. Fixes: 23192/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LIBFDK_AAC_fuzzer-5205702892322816 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
1 parent 5c144fd commit 3b9e867

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

libSACdec/src/sac_bitdec.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ SACDEC_ERROR SpatialDecParseSpecificConfig(
448448
int bsFreqRes, b3DaudioMode = 0;
449449
int numHeaderBits;
450450
int cfgStartPos, bitsAvailable;
451+
int treeConfig;
451452

452453
FDKmemclear(pSpatialSpecificConfig, sizeof(SPATIAL_SPECIFIC_CONFIG));
453454

@@ -488,13 +489,13 @@ SACDEC_ERROR SpatialDecParseSpecificConfig(
488489
pSpatialSpecificConfig->freqRes =
489490
(SPATIALDEC_FREQ_RES)freqResTable_LD[bsFreqRes];
490491

491-
pSpatialSpecificConfig->treeConfig =
492-
(SPATIALDEC_TREE_CONFIG)FDKreadBits(bitstream, 4);
492+
treeConfig = FDKreadBits(bitstream, 4);
493493

494-
if (pSpatialSpecificConfig->treeConfig != SPATIALDEC_MODE_RSVD7) {
494+
if (treeConfig != SPATIALDEC_MODE_RSVD7) {
495495
err = MPS_UNSUPPORTED_CONFIG;
496496
goto bail;
497497
}
498+
pSpatialSpecificConfig->treeConfig = (SPATIALDEC_TREE_CONFIG) treeConfig;
498499

499500
{
500501
pSpatialSpecificConfig->nOttBoxes =

0 commit comments

Comments
 (0)