Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] heap buffer overflow when last byte of SEI = 0xFF #425

Merged
merged 3 commits into from
Jun 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions tsMuxer/nalUnits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1998,20 +1998,23 @@ void SEIUnit::deserialize(SPSUnit& sps, int orig_hrd_parameters_present_flag)
while (curBuff < nalEnd - 1)
{
int payloadType = 0;
for (; *curBuff == 0xFF && curBuff < nalEnd; curBuff++) payloadType += 0xFF;
for (; curBuff < nalEnd && *curBuff == 0xFF; curBuff++) payloadType += 0xFF;
if (curBuff >= nalEnd)
return;
payloadType += *curBuff++;
if (curBuff >= nalEnd)
return;

int payloadSize = 0;
for (; *curBuff == 0xFF && curBuff < nalEnd; curBuff++) payloadSize += 0xFF;
for (; curBuff < nalEnd && *curBuff == 0xFF; curBuff++) payloadSize += 0xFF;
if (curBuff >= nalEnd)
return;
payloadSize += *curBuff++;
if (curBuff >= nalEnd)
if (nalEnd - curBuff < payloadSize - 1)
{
LTRACE(LT_WARN, 2, "Bad SEI detected. SEI too short");
return;
}
sei_payload(sps, payloadType, curBuff, payloadSize, orig_hrd_parameters_present_flag);
m_processedMessages.insert(payloadType);
curBuff += payloadSize;
Expand All @@ -2038,15 +2041,15 @@ int SEIUnit::isMVCSEI()
while (curBuff < nalEnd - 1)
{
int payloadType = 0;
for (; *curBuff == 0xFF && curBuff < nalEnd; curBuff++) payloadType += 0xFF;
for (; curBuff < nalEnd && *curBuff == 0xFF; curBuff++) payloadType += 0xFF;
if (curBuff >= nalEnd)
return NOT_ENOUGH_BUFFER;
payloadType += *curBuff++;
if (curBuff >= nalEnd)
return NOT_ENOUGH_BUFFER;

int payloadSize = 0;
for (; *curBuff == 0xFF && curBuff < nalEnd; curBuff++) payloadSize += 0xFF;
for (; curBuff < nalEnd && *curBuff == 0xFF; curBuff++) payloadSize += 0xFF;
if (curBuff >= nalEnd)
return NOT_ENOUGH_BUFFER;
payloadSize += *curBuff++;
Expand Down Expand Up @@ -2075,7 +2078,7 @@ int SEIUnit::removePicTimingSEI(SPSUnit& sps)
while (curBuff < nalEnd)
{
int payloadType = 0;
for (; *curBuff == 0xFF && curBuff < nalEnd; curBuff++)
for (; curBuff < nalEnd && *curBuff == 0xFF; curBuff++)
{
payloadType += 0xFF;
tmpBuffer[tmpBufferLen++] = 0xff;
Expand All @@ -2088,7 +2091,7 @@ int SEIUnit::removePicTimingSEI(SPSUnit& sps)
break;

int payloadSize = 0;
for (; *curBuff == 0xFF && curBuff < nalEnd; curBuff++)
for (; curBuff < nalEnd && *curBuff == 0xFF; curBuff++)
{
payloadSize += 0xFF;
tmpBuffer[tmpBufferLen++] = 0xff;
Expand Down