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

Showing the changes to libavcodec (2 of 2 files). Show all

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
449449 av_freep(&vps->hdr);
450450 }
451451
452+static 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+
452461 int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
453462 HEVCParamSets *ps)
454463 {
@@ -545,9 +554,11 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, · 90 unmodified lines
545554 goto err;
546555 }
547556
548− vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr));
549− if (!vps->hdr)
550− goto err;
557+ if (vps->vps_num_hrd_parameters) {
558+ vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr));
559+ if (!vps->hdr)
560+ goto err;
561+ }
551562
552563 for (i = 0; i < vps->vps_num_hrd_parameters; i++) {
553564 int common_inf_present = 1;
@@ -569,7 +580,7 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, · 15 unmodified lines
569580 }
570581
571582 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)) {
573584 ff_refstruct_unref(&vps);
574585 } else {
575586 remove_vps(ps, vps_id);
libavcodec/hevc_ps.h+3−1
@@ -153,7 +153,6 @@ typedef struct PTL { · 152 unmodified lines
153153
154154 typedef struct HEVCVPS {
155155 unsigned int vps_id;
156− HEVCHdrParams *hdr;
157156
158157 uint8_t vps_temporal_id_nesting_flag;
159158 int vps_max_layers;
@@ -175,6 +174,9 @@ typedef struct HEVCVPS { · 15 unmodified lines
175174
176175 uint8_t data[4096];
177176 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;
178180 } HEVCVPS;
179181
180182 typedef 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