History

avformat/mov: parse clap boxes that reference heif items

James Almer committed 2 years ago

Commit f225e6f1 parent ba6eeb21 file · +22 −10Browse files

Unified · Split

libavformat/mov.c+22−10
@@ -1234,14 +1234,26 @@ static int mov_read_wfex(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 1233 unmodified lines
1234static int mov_read_clap(MOVContext *c, AVIOContext *pb, MOVAtom atom)1234static int mov_read_clap(MOVContext *c, AVIOContext *pb, MOVAtom atom)
1235{1235{
1236 AVStream *st;1236 AVStream *st;
1237 HEIFItem *item;
1237 AVPacketSideData *sd;1238 AVPacketSideData *sd;
1239 int width, height;
1238 AVRational aperture_width, aperture_height, horiz_off, vert_off;1240 AVRational aperture_width, aperture_height, horiz_off, vert_off;
1239 AVRational pc_x, pc_y;1241 AVRational pc_x, pc_y;
1240 uint64_t top, bottom, left, right;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 return 0;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 aperture_width.num = avio_rb32(pb);1258 aperture_width.num = avio_rb32(pb);
1247 aperture_width.den = avio_rb32(pb);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 aperture_width.num, aperture_width.den, aperture_height.num, aperture_height.den,1275 aperture_width.num, aperture_width.den, aperture_height.num, aperture_height.den,
1264 horiz_off.num, horiz_off.den, vert_off.num, vert_off.den);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 pc_x = av_add_q(pc_x, horiz_off);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 pc_y = av_add_q(pc_y, vert_off);1281 pc_y = av_add_q(pc_y, vert_off);
1270 1282
1271 aperture_width = av_sub_q(aperture_width, (AVRational) { 1, 1 });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 top = av_q2d(av_sub_q(pc_y, aperture_height));1290 top = av_q2d(av_sub_q(pc_y, aperture_height));
1279 bottom = av_q2d(av_add_q(pc_y, aperture_height));1291 bottom = av_q2d(av_add_q(pc_y, aperture_height));
1280 1292
1281 if (bottom > (st->codecpar->height - 1) ||1293 if (bottom > (height - 1) ||
1282 right > (st->codecpar->width - 1))1294 right > (width - 1))
1283 return AVERROR_INVALIDDATA;1295 return AVERROR_INVALIDDATA;
1284 1296
1285 bottom = st->codecpar->height - 1 - bottom;1297 bottom = height - 1 - bottom;
1286 right = st->codecpar->width - 1 - right;1298 right = width - 1 - right;
1287 1299
1288 if (!(left | right | top | bottom))1300 if (!(left | right | top | bottom))
1289 return 0;1301 return 0;
1290 1302
1291 if ((left + right) >= st->codecpar->width ||1303 if ((left + right) >= width ||
1292 (top + bottom) >= st->codecpar->height)1304 (top + bottom) >= height)
1293 return AVERROR_INVALIDDATA;1305 return AVERROR_INVALIDDATA;
1294 1306
1295 sd = av_packet_side_data_new(&st->codecpar->coded_side_data,1307 sd = av_packet_side_data_new(&st->codecpar->coded_side_data,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t