History

pixdesc: Only check against valid entries when iterating over lists of enums

Some of these enums have gaps in between their values, since they correspond to the values in various specs, instead of being an incrementing list. Fixes segfaults when, for example, using the valid API call: av_color_primaries_from_name("jecdec-p22");

Derek Buitenhuis committed 8 years ago

Commit 238a8ae1 parent 8c20ea81 file · +24 −4Browse files

Unified · Split

libavutil/pixdesc.c+24−4
@@ -2737,7 +2737,12 @@ int av_color_primaries_from_name(const char *name) · 2736 unmodified lines
27372737 int i;
27382738
27392739 for (i = 0; i < FF_ARRAY_ELEMS(color_primaries_names); i++) {
2740− size_t len = strlen(color_primaries_names[i]);
2740+ size_t len;
2741+
2742+ if (!color_primaries_names[i])
2743+ continue;
2744+
2745+ len = strlen(color_primaries_names[i]);
27412746 if (!strncmp(color_primaries_names[i], name, len))
27422747 return i;
27432748 }
@@ -2756,7 +2761,12 @@ int av_color_transfer_from_name(const char *name) · 12 unmodified lines
27562761 int i;
27572762
27582763 for (i = 0; i < FF_ARRAY_ELEMS(color_transfer_names); i++) {
2759− size_t len = strlen(color_transfer_names[i]);
2764+ size_t len;
2765+
2766+ if (!color_transfer_names[i])
2767+ continue;
2768+
2769+ len = strlen(color_transfer_names[i]);
27602770 if (!strncmp(color_transfer_names[i], name, len))
27612771 return i;
27622772 }
@@ -2775,7 +2785,12 @@ int av_color_space_from_name(const char *name) · 12 unmodified lines
27752785 int i;
27762786
27772787 for (i = 0; i < FF_ARRAY_ELEMS(color_space_names); i++) {
2778− size_t len = strlen(color_space_names[i]);
2788+ size_t len;
2789+
2790+ if (!color_space_names[i])
2791+ continue;
2792+
2793+ len = strlen(color_space_names[i]);
27792794 if (!strncmp(color_space_names[i], name, len))
27802795 return i;
27812796 }
@@ -2794,7 +2809,12 @@ int av_chroma_location_from_name(const char *name) · 12 unmodified lines
27942809 int i;
27952810
27962811 for (i = 0; i < FF_ARRAY_ELEMS(chroma_location_names); i++) {
2797− size_t len = strlen(chroma_location_names[i]);
2812+ size_t len;
2813+
2814+ if (!chroma_location_names[i])
2815+ continue;
2816+
2817+ len = strlen(chroma_location_names[i]);
27982818 if (!strncmp(chroma_location_names[i], name, len))
27992819 return i;
28002820 }

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