Browse code

nutdec: reject negative value_len in read_sm_data

If it is negative, it can cause the byte position to move backwards in
avio_skip, which in turn makes sm_size negative and thus size larger
than the size of the packet buffer, causing invalid writes in avio_read.

Also fix potential overflow of avio_tell(bc) + value_len.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
(cherry picked from commit ce10f572c12b0d172c72d31d8c979afce602bf0c)
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>

Andreas Cadhalpun authored on 2015/12/19 20:02:56
Showing 1 changed files
... ...
@@ -872,7 +872,7 @@ static int read_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int
872 872
 
873 873
             get_str(bc, type_str, sizeof(type_str));
874 874
             value_len = ffio_read_varlen(bc);
875
-            if (avio_tell(bc) + value_len >= maxpos)
875
+            if (value_len < 0 || value_len >= maxpos - avio_tell(bc))
876 876
                 return AVERROR_INVALIDDATA;
877 877
             if (!strcmp(name, "Palette")) {
878 878
                 dst = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, value_len);