History

avformat/hls: Return error code when read key file failed

Zhao Zhili committed 1 year ago

Commit 1cda5fe1 parent 40147841 file · +34 −13Browse files

Unified · Split

libavformat/hls.c+34−13
@@ -1336,6 +1336,37 @@ static void intercept_id3(struct playlist *pls, uint8_t *buf, · 1335 unmodified lines
1336 pls->is_id3_timestamped = (pls->id3_mpegts_timestamp != AV_NOPTS_VALUE);1336 pls->is_id3_timestamped = (pls->id3_mpegts_timestamp != AV_NOPTS_VALUE);
1337}1337}
1338 1338
1339static int read_key(HLSContext *c, struct playlist *pls, struct segment *seg)
1340{
1341 AVIOContext *pb = NULL;
1342
1343 int ret = open_url(pls->parent, &pb, seg->key, &c->avio_opts, NULL, NULL);
1344 if (ret < 0) {
1345 av_log(pls->parent, AV_LOG_ERROR, "Unable to open key file %s, %s\n",
1346 seg->key, av_err2str(ret));
1347 return ret;
1348 }
1349
1350 ret = avio_read(pb, pls->key, sizeof(pls->key));
1351 ff_format_io_close(pls->parent, &pb);
1352 if (ret != sizeof(pls->key)) {
1353 if (ret < 0) {
1354 av_log(pls->parent, AV_LOG_ERROR, "Unable to read key file %s, %s\n",
1355 seg->key, av_err2str(ret));
1356 } else {
1357 av_log(pls->parent, AV_LOG_ERROR, "Unable to read key file %s, read bytes %d != %zu\n",
1358 seg->key, ret, sizeof(pls->key));
1359 ret = AVERROR_INVALIDDATA;
1360 }
1361
1362 return ret;
1363 }
1364
1365 av_strlcpy(pls->key_url, seg->key, sizeof(pls->key_url));
1366
1367 return 0;
1368}
1369
1339static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg, AVIOContext **in)1370static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg, AVIOContext **in)
1340{1371{
1341 AVDictionary *opts = NULL;1372 AVDictionary *opts = NULL;
@@ -1357,19 +1388,9 @@ static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg, · 15 unmodified lines
1357 1388
1358 if (seg->key_type == KEY_AES_128 || seg->key_type == KEY_SAMPLE_AES) {1389 if (seg->key_type == KEY_AES_128 || seg->key_type == KEY_SAMPLE_AES) {
1359 if (strcmp(seg->key, pls->key_url)) {1390 if (strcmp(seg->key, pls->key_url)) {
1360 AVIOContext *pb = NULL;1391 ret = read_key(c, pls, seg);
1361 if (open_url(pls->parent, &pb, seg->key, &c->avio_opts, NULL, NULL) == 0) {1392 if (ret < 0)
1362 ret = avio_read(pb, pls->key, sizeof(pls->key));1393 goto cleanup;
1363 if (ret != sizeof(pls->key)) {
1364 av_log(pls->parent, AV_LOG_ERROR, "Unable to read key file %s\n",
1365 seg->key);
1366 }
1367 ff_format_io_close(pls->parent, &pb);
1368 } else {
1369 av_log(pls->parent, AV_LOG_ERROR, "Unable to open key file %s\n",
1370 seg->key);
1371 }
1372 av_strlcpy(pls->key_url, seg->key, sizeof(pls->key_url));
1373 }1394 }
1374 }1395 }
1375 1396

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