For a corrupted stream, the value of nalu_len read from the extradata is not reliable. We need to perform additional checks
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -65,9 +65,11 @@ static int hevc_extradata_to_annexb(AVBSFContext *ctx) · 64 unmodified lines | ||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | for (j = 0; j < cnt; j++) { |
| 68 | − int nalu_len = bytestream2_get_be16(&gb); | |
| 68 | + const int nalu_len = bytestream2_get_be16(&gb); | |
| 69 | 69 | |
| 70 | − if (4 + AV_INPUT_BUFFER_PADDING_SIZE + nalu_len > SIZE_MAX - new_extradata_size) { | |
| 70 | + if (!nalu_len || | |
| 71 | + nalu_len > bytestream2_get_bytes_left(&gb) || | |
| 72 | + 4 + AV_INPUT_BUFFER_PADDING_SIZE + nalu_len > SIZE_MAX - new_extradata_size) { | |
| 71 | 73 | ret = AVERROR_INVALIDDATA; |
| 72 | 74 | goto fail; |
| 73 | 75 | } |