Unified · Split
| @@ -1234,14 +1234,26 @@ static int mov_read_wfex(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 1233 unmodified lines | ||
| 1234 | 1234 | static int mov_read_clap(MOVContext *c, AVIOContext *pb, MOVAtom atom) |
| 1235 | 1235 | { |
| 1236 | 1236 | AVStream *st; |
| 1237 | + HEIFItem *item; | |
| 1237 | 1238 | AVPacketSideData *sd; |
| 1239 | + int width, height; | |
| 1238 | 1240 | AVRational aperture_width, aperture_height, horiz_off, vert_off; |
| 1239 | 1241 | AVRational pc_x, pc_y; |
| 1240 | 1242 | uint64_t top, bottom, left, right; |
| 1241 | 1243 | |
| 1242 | − if (c->fc->nb_streams < 1) | |
| 1244 | + item = heif_cur_item(c); | |
| 1245 | + st = get_curr_st(c); | |
| 1246 | + if (!st) | |
| 1243 | 1247 | return 0; |
| 1244 | − st = c->fc->streams[c->fc->nb_streams-1]; | |
| 1248 | + | |
| 1249 | + width = st->codecpar->width; | |
| 1250 | + height = st->codecpar->height; | |
| 1251 | + if ((!width || !height) && item) { | |
| 1252 | + width = item->width; | |
| 1253 | + height = item->height; | |
| 1254 | + } | |
| 1255 | + if (!width || !height) | |
| 1256 | + return AVERROR_INVALIDDATA; | |
| 1245 | 1257 | |
| 1246 | 1258 | aperture_width.num = avio_rb32(pb); |
| 1247 | 1259 | aperture_width.den = avio_rb32(pb); |
| @@ -1263,9 +1275,9 @@ static int mov_read_clap(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 15 unmodified lines | ||
| 1263 | 1275 | aperture_width.num, aperture_width.den, aperture_height.num, aperture_height.den, |
| 1264 | 1276 | horiz_off.num, horiz_off.den, vert_off.num, vert_off.den); |
| 1265 | 1277 | |
| 1266 | − pc_x = av_mul_q((AVRational) { st->codecpar->width - 1, 1 }, (AVRational) { 1, 2 }); | |
| 1278 | + pc_x = av_mul_q((AVRational) { width - 1, 1 }, (AVRational) { 1, 2 }); | |
| 1267 | 1279 | pc_x = av_add_q(pc_x, horiz_off); |
| 1268 | − pc_y = av_mul_q((AVRational) { st->codecpar->height - 1, 1 }, (AVRational) { 1, 2 }); | |
| 1280 | + pc_y = av_mul_q((AVRational) { height - 1, 1 }, (AVRational) { 1, 2 }); | |
| 1269 | 1281 | pc_y = av_add_q(pc_y, vert_off); |
| 1270 | 1282 | |
| 1271 | 1283 | aperture_width = av_sub_q(aperture_width, (AVRational) { 1, 1 }); |
| @@ -1278,18 +1290,18 @@ static int mov_read_clap(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 6 unmodified lines | ||
| 1278 | 1290 | top = av_q2d(av_sub_q(pc_y, aperture_height)); |
| 1279 | 1291 | bottom = av_q2d(av_add_q(pc_y, aperture_height)); |
| 1280 | 1292 | |
| 1281 | − if (bottom > (st->codecpar->height - 1) || | |
| 1282 | − right > (st->codecpar->width - 1)) | |
| 1293 | + if (bottom > (height - 1) || | |
| 1294 | + right > (width - 1)) | |
| 1283 | 1295 | return AVERROR_INVALIDDATA; |
| 1284 | 1296 | |
| 1285 | − bottom = st->codecpar->height - 1 - bottom; | |
| 1286 | − right = st->codecpar->width - 1 - right; | |
| 1297 | + bottom = height - 1 - bottom; | |
| 1298 | + right = width - 1 - right; | |
| 1287 | 1299 | |
| 1288 | 1300 | if (!(left | right | top | bottom)) |
| 1289 | 1301 | return 0; |
| 1290 | 1302 | |
| 1291 | − if ((left + right) >= st->codecpar->width || | |
| 1292 | − (top + bottom) >= st->codecpar->height) | |
| 1303 | + if ((left + right) >= width || | |
| 1304 | + (top + bottom) >= height) | |
| 1293 | 1305 | return AVERROR_INVALIDDATA; |
| 1294 | 1306 | |
| 1295 | 1307 | sd = av_packet_side_data_new(&st->codecpar->coded_side_data, |