Skip to content

Commit

Permalink
WIP Security improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dnewman-gpsw committed Jun 29, 2021
1 parent 9785875 commit 2766809
Show file tree
Hide file tree
Showing 11 changed files with 443 additions and 223 deletions.
3 changes: 2 additions & 1 deletion Codec/InvertHorizontalStrip16s.c
Original file line number Diff line number Diff line change
Expand Up @@ -17563,7 +17563,8 @@ InvertHorizontalStrip16sYUVtoRGB(HorizontalFilterParams)

newstrip.width = roi.width*2;
newstrip.height = roi.height;
ConvertRow16uToDitheredBuffer(decoder, plane_array, plane_pitch, newstrip,
if(channels >= 3)
ConvertRow16uToDitheredBuffer(decoder, plane_array, plane_pitch, newstrip,
output_image, output_pitch, newstrip.width*2,
format, decoder->frame.colorspace);
}
Expand Down
16 changes: 10 additions & 6 deletions Codec/bitstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,9 @@ TAGWORD GetValue(BITSTREAM *stream, int tag)
{
TAGVALUE segment = GetTagValue(stream);

assert(stream->error == BITSTREAM_ERROR_OKAY);
//assert(stream->error == BITSTREAM_ERROR_OKAY);
if (stream->error == BITSTREAM_ERROR_OKAY) {
assert(segment.tuple.tag == tag);
//assert(segment.tuple.tag == tag);
if (segment.tuple.tag == tag) {
return segment.tuple.value;
}
Expand Down Expand Up @@ -561,8 +561,8 @@ int GetWord16s(BITSTREAM *stream)
assert(stream->nBitsFree == BITSTREAM_LONG_SIZE);

// Check that there is something in the block
assert(nWordsUsed >= nWordsPerValue);
if (nWordsUsed >= nWordsPerValue)
//assert(nWordsUsed >= nWordsPerValue);
if (nWordsUsed >= nWordsPerValue && nWordsUsed < stream->dwBlockLength)
{
// Get the first byte from the bitstream
value = *(lpCurrentWord++);
Expand Down Expand Up @@ -1517,8 +1517,12 @@ void AlignBitsTag(BITSTREAM *stream)
}

// Check that the bitstream is long word aligned
assert(((uintptr_t)lpCurrentWord & BITSTREAM_LONG_MASK) == (unsigned)offset);
assert(((uintptr_t)nWordsUsed & BITSTREAM_LONG_MASK) == 0);
//assert(((uintptr_t)lpCurrentWord & BITSTREAM_LONG_MASK) == (unsigned)offset);
//assert(((uintptr_t)nWordsUsed & BITSTREAM_LONG_MASK) == 0);
if (((uintptr_t)lpCurrentWord & BITSTREAM_LONG_MASK) != (unsigned)offset)
stream->error = 1;
if (((uintptr_t)nWordsUsed & BITSTREAM_LONG_MASK) != 0)
stream->error = 1;

// Update the bitstream pointer
stream->lpCurrentWord = lpCurrentWord;
Expand Down
10 changes: 5 additions & 5 deletions Codec/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ int FindNextSample(BITSTREAM *stream)
return SAMPLE_TYPE_NONE;

// Return null sample if that tag does not specify the sample type
assert(segment.tuple.tag == CODEC_TAG_SAMPLE);
//assert(segment.tuple.tag == CODEC_TAG_SAMPLE);
if (segment.tuple.tag != CODEC_TAG_SAMPLE)
return SAMPLE_TYPE_NONE;

Expand Down Expand Up @@ -2020,8 +2020,8 @@ CODEC_ERROR DecodeFrameHeader(BITSTREAM *stream, FRAME_HEADER *header, int sampl
{
case SAMPLE_TYPE_NONE: // Caller has not read the bitstream marker
segment = GetTagValue(stream);
assert(segment.tuple.tag == CODEC_TAG_SAMPLE);
assert(segment.tuple.value == SAMPLE_TYPE_FRAME);
//assert(segment.tuple.tag == CODEC_TAG_SAMPLE);
//assert(segment.tuple.value == SAMPLE_TYPE_FRAME);
if (!IsTagValue(segment, CODEC_TAG_SAMPLE, SAMPLE_TYPE_FRAME)) {
error = CODEC_ERROR_FRAME_START_MARKER;
return error;
Expand Down Expand Up @@ -2609,8 +2609,8 @@ CODEC_ERROR DecodeBandTrailer(BITSTREAM *stream, BAND_TRAILER *trailer)
#if (_CODEC_MARKERS && CODEC_BAND_END_CODE)
// Read the debugging marker
segment = GetTagValue(stream);
assert(segment.tuple.tag == CODEC_TAG_BAND_TRAILER);
assert(segment.tuple.value == 0);
//assert(segment.tuple.tag == CODEC_TAG_BAND_TRAILER);
//assert(segment.tuple.value == 0);
if (!IsTagValue(segment, CODEC_TAG_BAND_TRAILER, 0)) {
error = CODEC_ERROR_BAND_END_MARKER;
return error;
Expand Down
2 changes: 1 addition & 1 deletion Codec/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -10727,7 +10727,7 @@ void ConvertRow16uToDitheredRGB(DECODER *decoder, uint8_t *planar_output[], int
saturate = 1;
break;

default: assert(0);
default:// assert(0);
case COLOR_SPACE_CG_709:
y_offset = 16;
ymult = 128*149; //7bit 1.164
Expand Down
Loading

0 comments on commit 2766809

Please sign in to comment.