From 9492b0d90544eba37f9e10715775a2e5f14f745f Mon Sep 17 00:00:00 2001 From: Jonjo McKay Date: Thu, 20 Feb 2014 11:02:32 +0000 Subject: [PATCH 1/2] Updated getYear() to check for both 'year' and 'date' keys to fix segfault --- ffmpeg_movie.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ffmpeg_movie.c b/ffmpeg_movie.c index 91b5c6e..ef24979 100644 --- a/ffmpeg_movie.c +++ b/ffmpeg_movie.c @@ -584,12 +584,29 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getTrackNumber) } /* }}} */ +static const char *_php_get_year(ff_movie_context *ffmovie_ctx) +{ + AVDictionaryEntry *year = av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "year", NULL, 0); + + if (!year) { + year = av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "date", NULL, 0); + } + + return year->value; +} + /* {{{ proto int getYear() * Return ID3 year field from an mp3 file */ FFMPEG_PHP_METHOD(ffmpeg_movie, getYear) { - php_get_dict_value(INTERNAL_FUNCTION_PARAM_PASSTHRU, "year"); + ff_movie_context *ffmovie_ctx; + + GET_MOVIE_RESOURCE(ffmovie_ctx); + + const char *year = _php_get_year(ffmovie_ctx); + + RETURN_STRINGL(year, strlen(year), 1); } /* }}} */ From 897b092930e776f7a797fff7302c5701517ab8c8 Mon Sep 17 00:00:00 2001 From: Jonjo McKay Date: Thu, 20 Feb 2014 15:29:51 +0000 Subject: [PATCH 2/2] Some more terrible C to handle neither 'date' nor 'year' existing --- ffmpeg_movie.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ffmpeg_movie.c b/ffmpeg_movie.c index ef24979..525d5a9 100644 --- a/ffmpeg_movie.c +++ b/ffmpeg_movie.c @@ -585,13 +585,17 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getTrackNumber) /* }}} */ static const char *_php_get_year(ff_movie_context *ffmovie_ctx) -{ +{ AVDictionaryEntry *year = av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "year", NULL, 0); if (!year) { year = av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "date", NULL, 0); } + if (!year) { + return NULL; + } + return year->value; } @@ -606,6 +610,10 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getYear) const char *year = _php_get_year(ffmovie_ctx); + if (!year) { + RETURN_FALSE; + } + RETURN_STRINGL(year, strlen(year), 1); } /* }}} */