summaryrefslogtreecommitdiff
path: root/libavformat/matroskadec.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2021-02-16 15:34:06 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2021-02-22 03:57:52 +0100
commite8f390160438923ae2dadfe1dc44bb3211a587ee (patch)
tree5411bfc565563e2a45f2bacf140bdc5a96b29926 /libavformat/matroskadec.c
parent5b9a0e6031eee5df2e0d6a35862908c6a017f490 (diff)
avformat/matroskadec: Check min_luminance more thoroughly
In the absence of an explicitly coded minimal luminance, the current code inferred it to be -1, an invalid value. Yet it did not check the value lateron at all, so that if a valid maximum luminance is encountered, but no minimal luminance, an invalid minimal luminance of -1 is exported. If an minimal luminance element with a negative value is present, it is exported, too. This can be simply fixed by adding a check for the value of the element. Yet given that a minimal luminance of zero Cd/m² is legal and can be coded with a length of zero, we must not use a fake default value to find out whether the element is present or not. Therefore this patch uses an explicit counter for it. While just at it, also check for max_luminance > min_luminance. Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavformat/matroskadec.c')
-rw-r--r--libavformat/matroskadec.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index ceb054e8ab..e6f4faa337 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -168,7 +168,7 @@ typedef struct MatroskaMasteringMeta {
double white_x;
double white_y;
double max_luminance;
- double min_luminance;
+ CountedElement min_luminance;
} MatroskaMasteringMeta;
typedef struct MatroskaTrackVideoColor {
@@ -452,7 +452,7 @@ static EbmlSyntax matroska_mastering_meta[] = {
{ MATROSKA_ID_VIDEOCOLOR_BY, EBML_FLOAT, 0, 0, offsetof(MatroskaMasteringMeta, b_y) },
{ MATROSKA_ID_VIDEOCOLOR_WHITEX, EBML_FLOAT, 0, 0, offsetof(MatroskaMasteringMeta, white_x) },
{ MATROSKA_ID_VIDEOCOLOR_WHITEY, EBML_FLOAT, 0, 0, offsetof(MatroskaMasteringMeta, white_y) },
- { MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN, EBML_FLOAT, 0, 0, offsetof(MatroskaMasteringMeta, min_luminance), { .f=-1 } },
+ { MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN, EBML_FLOAT, 1, 0, offsetof(MatroskaMasteringMeta, min_luminance) },
{ MATROSKA_ID_VIDEOCOLOR_LUMINANCEMAX, EBML_FLOAT, 0, 0, offsetof(MatroskaMasteringMeta, max_luminance) },
CHILD_OF(matroska_track_video_color)
};
@@ -2110,7 +2110,10 @@ static int mkv_parse_video_color(AVStream *st, const MatroskaTrack *track) {
mastering_meta->g_x > 0 && mastering_meta->g_y > 0 &&
mastering_meta->b_x > 0 && mastering_meta->b_y > 0 &&
mastering_meta->white_x > 0 && mastering_meta->white_y > 0;
- has_mastering_luminance = mastering_meta->max_luminance > 0;
+ has_mastering_luminance = mastering_meta->max_luminance >
+ mastering_meta->min_luminance.el.f &&
+ mastering_meta->min_luminance.el.f >= 0 &&
+ mastering_meta->min_luminance.count;
if (color->matrix_coefficients != AVCOL_SPC_RESERVED)
st->codecpar->color_space = color->matrix_coefficients;
@@ -2169,7 +2172,7 @@ static int mkv_parse_video_color(AVStream *st, const MatroskaTrack *track) {
}
if (has_mastering_luminance) {
metadata->max_luminance = av_d2q(mastering_meta->max_luminance, INT_MAX);
- metadata->min_luminance = av_d2q(mastering_meta->min_luminance, INT_MAX);
+ metadata->min_luminance = av_d2q(mastering_meta->min_luminance.el.f, INT_MAX);
metadata->has_luminance = 1;
}
}