History

avcodec/hevc_ps: fix the problem of memcmp losing effectiveness

HEVCHdrParams* receives a pointer which points to a dynamically allocated memory block. It causes the memcmp always returning 1. Add a function to do the comparision. A condition is also added to avoid malloc(0).

Tong Wu committed 2 years ago

Commit 6bf17131 parent fa110c32 files · +18 −5Browse files

Unified · Split

2 files
  1. libavcodec/hevc_ps.c +15 −4
  2. libavcodec/hevc_ps.h +3 −1
libavcodec/hevc_ps.c+15−4
@@ -449,6 +449,15 @@ static void uninit_vps(FFRefStructOpaque opaque, void *obj) · 448 unmodified lines
449 av_freep(&vps->hdr);449 av_freep(&vps->hdr);
450}450}
451 451
452static int compare_vps(const HEVCVPS *vps1, const HEVCVPS *vps2)
453{
454 if (!memcmp(vps1, vps2, offsetof(HEVCVPS, hdr)))
455 return !vps1->vps_num_hrd_parameters ||
456 !memcmp(vps1->hdr, vps2->hdr, vps1->vps_num_hrd_parameters * sizeof(*vps1->hdr));
457
458 return 0;
459}
460
452int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,461int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
453 HEVCParamSets *ps)462 HEVCParamSets *ps)
454{463{
@@ -545,9 +554,11 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, · 90 unmodified lines
545 goto err;554 goto err;
546 }555 }
547 556
548 vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr));557 if (vps->vps_num_hrd_parameters) {
549 if (!vps->hdr)558 vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr));
550 goto err;559 if (!vps->hdr)
560 goto err;
561 }
551 562
552 for (i = 0; i < vps->vps_num_hrd_parameters; i++) {563 for (i = 0; i < vps->vps_num_hrd_parameters; i++) {
553 int common_inf_present = 1;564 int common_inf_present = 1;
@@ -569,7 +580,7 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, · 15 unmodified lines
569 }580 }
570 581
571 if (ps->vps_list[vps_id] &&582 if (ps->vps_list[vps_id] &&
572 !memcmp(ps->vps_list[vps_id], vps, sizeof(*vps))) {583 compare_vps(ps->vps_list[vps_id], vps)) {
573 ff_refstruct_unref(&vps);584 ff_refstruct_unref(&vps);
574 } else {585 } else {
575 remove_vps(ps, vps_id);586 remove_vps(ps, vps_id);
libavcodec/hevc_ps.h+3−1
@@ -153,7 +153,6 @@ typedef struct PTL { · 152 unmodified lines
153 153
154typedef struct HEVCVPS {154typedef struct HEVCVPS {
155 unsigned int vps_id;155 unsigned int vps_id;
156 HEVCHdrParams *hdr;
157 156
158 uint8_t vps_temporal_id_nesting_flag;157 uint8_t vps_temporal_id_nesting_flag;
159 int vps_max_layers;158 int vps_max_layers;
@@ -175,6 +174,9 @@ typedef struct HEVCVPS { · 15 unmodified lines
175 174
176 uint8_t data[4096];175 uint8_t data[4096];
177 int data_size;176 int data_size;
177 /* Put this at the end of the structure to make it easier to calculate the
178 * size before this pointer, which is used for memcmp */
179 HEVCHdrParams *hdr;
178} HEVCVPS;180} HEVCVPS;
179 181
180typedef struct ScalingList {182typedef struct ScalingList {

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