Skip to content

Commit 92df299

Browse files
stellawuintelgfxVPLsdm
authored andcommitted
[Decode] Fix Coverity static analysis issues in decode component
Fix 11 Coverity defects in the Decode component across MJPEG, JXS, AV1, H264, and H265 decoders. Also fix scan-modified-class: use RT_FUNC_ENTER(CheckGUID) and add OFFSET_FUNC_CheckGUID to mfx_smartv_trace_offset.h. MISSING_LOCK (data race condition) fixes: - CID 3583175: Add m_mGuard lock to VideoDECODEMJPEG::Reset(), which also covers IsSameVideoParam() accessing m_response without lock - CID 3583205: Same Reset() lock fix covers m_platform access - CID 3583326: Add m_mGuard lock to JXS decoder Reset() for m_core access - CID 3583328: Add m_mGuard lock to JXS decoder DecodeFrameCheck() for m_core access - CID 3583455: Add guard lock to AV1Decoder::GetCurrFrame() for lastest_submitted_frame access - CID 3583545: Same JXS Reset() lock fix covers m_platform access INTEGER_OVERFLOW fixes: - CID 3515335: Guard against l==0 in read_uniform() to prevent uint32_t underflow on l-1 when GetUnsignedBits(n)==0 - CID 3535741: Change loop variable sliceId from uint32_t to int32_t in H265DecoderFrameInfo::EliminateErrors() to avoid wrap-around overflow when resetting to -1 before continue - CID 3541793: Change loop variable sliceId from size_t to ptrdiff_t in SetOfSlices::CleanUseless() to avoid underflow on --sliceId - CID 3553573: Change loop variable pos from size_t to ptrdiff_t in AccessUnit::CleanUseless() to avoid underflow on pos-- - CID 3556511: Add explicit (int32_t) cast in DecodeExpGolombOne_H264_1u32s() when assigning uint32_t sentinel value 0xFFFFFFFF to int32_t *pDst
1 parent 8e7d61c commit 92df299

6 files changed

Lines changed: 17 additions & 10 deletions

File tree

_studio/mfx_lib/decode/mjpeg/src/mfx_mjpeg_dec_decode.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ mfxStatus VideoDECODEMJPEG::Reset(mfxVideoParam *par)
300300
TRACE_EVENT(MFX_TRACE_API_DECODE_RESET_TASK, EVENT_TYPE_START, TR_KEY_MFX_API, make_event_data(par ? par->mfx.FrameInfo.Width : 0,
301301
par ? par->mfx.FrameInfo.Height : 0, par ? par->mfx.CodecId : 0));
302302

303+
std::lock_guard<std::mutex> guard(m_mGuard);
304+
303305
MFX_CHECK(m_isInit, MFX_ERR_NOT_INITIALIZED);
304306

305307
MFX_CHECK_NULL_PTR1(par);

_studio/shared/umc/codec/av1_dec/include/umc_av1_bitstream_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ namespace UMC_AV1_DECODER
4343
inline int32_t read_uniform(AV1Bitstream& bs, uint32_t n)
4444
{
4545
const uint32_t l = UMC_VP9_DECODER::GetUnsignedBits(n);
46+
if (l == 0)
47+
return 0;
4648
const uint32_t m = (1 << l) - n;
4749
const uint32_t v = bs.GetBits(l - 1);
4850
if (v < m)

_studio/shared/umc/codec/av1_dec/include/umc_av1_decoder.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ namespace UMC_AV1_DECODER
163163
AV1DecoderFrame* DecodeFrameID(UMC::FrameMemID);
164164
AV1DecoderFrame* FindFrameInProgress();
165165
AV1DecoderFrame* GetCurrFrame()
166-
{ return lastest_submitted_frame; }
166+
{
167+
std::lock_guard<std::mutex> lg(guard);
168+
return lastest_submitted_frame;
169+
}
167170
UMC::FrameMemID GetRepeatedFrame(){return repeateFrame;}
168171
void SetInFrameRate(mfxF64 rate)
169172
{ in_framerate = rate; }

_studio/shared/umc/codec/h264_dec/include/umc_h264_bitstream_headers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ inline bool DecodeExpGolombOne_H264_1u32s (uint32_t **ppBitStream,
391391
if ((bool)(isSigned) == true)
392392
*pDst = (sval & 1UL) ? (int32_t)((sval >> 1) + 1) : -(int32_t)(sval >> 1);
393393
else
394-
*pDst = sval;
394+
*pDst = (int32_t)sval;
395395
}
396396
return true;
397397
}

_studio/shared/umc/codec/h264_dec/src/umc_h264_au_splitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ void SetOfSlices::AddSet(const SetOfSlices *set)
223223
void SetOfSlices::CleanUseless()
224224
{
225225
size_t count = m_pSliceQueue.size();
226-
for (size_t sliceId = 0; sliceId < count; sliceId++)
226+
for (ptrdiff_t sliceId = 0; sliceId < static_cast<ptrdiff_t>(count); sliceId++)
227227
{
228228
H264Slice * curSlice = m_pSliceQueue[sliceId];
229229
if (curSlice->m_bDecoded)
@@ -328,7 +328,7 @@ size_t AccessUnit::GetLayersCount() const
328328
void AccessUnit::CleanUseless()
329329
{
330330
size_t count = m_layers.size();
331-
for (size_t pos = 0; pos < count; pos++)
331+
for (ptrdiff_t pos = 0; pos < static_cast<ptrdiff_t>(count); pos++)
332332
{
333333
SetOfSlices * set = &m_layers[pos];
334334
set->CleanUseless();

_studio/shared/umc/codec/h265_dec/src/umc_h265_frame_info.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ void H265DecoderFrameInfo::EliminateErrors()
102102
return;
103103

104104
// Remove dependent slices without a corresponding independent slice
105-
for (uint32_t sliceId = 0; sliceId < GetSliceCount(); sliceId++)
105+
for (int32_t sliceId = 0; sliceId < static_cast<int32_t>(GetSliceCount()); sliceId++)
106106
{
107107
H265Slice * slice = GetSlice(sliceId);
108108

109109
if (slice->GetSliceHeader()->dependent_slice_segment_flag)
110110
{
111111
RemoveSlice(sliceId);
112-
sliceId = uint32_t(-1);
112+
sliceId = -1;
113113
continue;
114114
}
115115
else
@@ -121,7 +121,7 @@ void H265DecoderFrameInfo::EliminateErrors()
121121
H265Slice *baseSlice = GetSlice(0); // after the for() loop above ,the first slice is treated as 'base' slice
122122

123123
bool bIndepSliceMissing = false;
124-
for (uint32_t sliceId = 1; sliceId < GetSliceCount(); sliceId++)
124+
for (int32_t sliceId = 1; sliceId < static_cast<int32_t>(GetSliceCount()); sliceId++)
125125
{
126126
H265SliceHeader *sliceHeader = GetSlice(sliceId)->GetSliceHeader();
127127

@@ -144,7 +144,7 @@ void H265DecoderFrameInfo::EliminateErrors()
144144
}
145145

146146
// Remove slices with duplicated slice_segment_address syntax
147-
for (uint32_t sliceId = 0; sliceId < GetSliceCount(); sliceId++)
147+
for (int32_t sliceId = 0; sliceId < static_cast<int32_t>(GetSliceCount()); sliceId++)
148148
{
149149
H265Slice * slice = m_pSliceQueue[sliceId];
150150
H265Slice * nextSlice = GetSlice(sliceId + 1);
@@ -154,7 +154,7 @@ void H265DecoderFrameInfo::EliminateErrors()
154154

155155
if (slice->GetFirstMB() == slice->GetMaxMB())
156156
{
157-
uint32_t sliceIdToRemove;
157+
int32_t sliceIdToRemove;
158158

159159
// Heuristic logic:
160160
if (slice->GetSliceHeader()->dependent_slice_segment_flag && !nextSlice->GetSliceHeader()->dependent_slice_segment_flag)
@@ -168,7 +168,7 @@ void H265DecoderFrameInfo::EliminateErrors()
168168
sliceIdToRemove = sliceId + 1;
169169
}
170170
RemoveSlice(sliceIdToRemove);
171-
sliceId = uint32_t(-1);
171+
sliceId = -1;
172172
continue;
173173
}
174174
}

0 commit comments

Comments
 (0)