From 3f258f5ee05c9da05f61447b802ae3e39629f44b Mon Sep 17 00:00:00 2001 From: James Almer Date: Fri, 10 Feb 2017 20:24:26 -0300 Subject: [PATCH 1/2] apetag: fix flag value to signal footer presence According to the spec[1], a value of 0 means the footer is present and a value of 1 means it's absent, the exact opposite of header presence flag where 1 means present and 0 absent. The reason for this is compatibility with APEv1 tags, where there's no header, footer presence was mandatory for all files, and the flags field was a zeroed reserved field. [1] http://wiki.hydrogenaud.io/index.php?title=Ape_Tags_Flags Signed-off-by: James Almer CC: libav-stable@libav.org Signed-off-by: Anton Khirnov --- libavformat/apetag.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libavformat/apetag.c b/libavformat/apetag.c index 05430dd9bc..93a4fb3430 100644 --- a/libavformat/apetag.c +++ b/libavformat/apetag.c @@ -32,7 +32,7 @@ #define APE_TAG_VERSION 2000 #define APE_TAG_FOOTER_BYTES 32 #define APE_TAG_FLAG_CONTAINS_HEADER (1 << 31) -#define APE_TAG_FLAG_CONTAINS_FOOTER (1 << 30) +#define APE_TAG_FLAG_LACKS_FOOTER (1 << 30) #define APE_TAG_FLAG_IS_HEADER (1 << 29) #define APE_TAG_FLAG_IS_BINARY (1 << 1) @@ -194,8 +194,7 @@ int ff_ape_write_tag(AVFormatContext *s) avio_wl32(s->pb, 0); // reserve space for tag count // flags - avio_wl32(s->pb, APE_TAG_FLAG_CONTAINS_HEADER | APE_TAG_FLAG_CONTAINS_FOOTER | - APE_TAG_FLAG_IS_HEADER); + avio_wl32(s->pb, APE_TAG_FLAG_CONTAINS_HEADER | APE_TAG_FLAG_IS_HEADER); ffio_fill(s->pb, 0, 8); // reserved while ((e = av_dict_get(s->metadata, "", e, AV_DICT_IGNORE_SUFFIX))) { @@ -217,7 +216,7 @@ int ff_ape_write_tag(AVFormatContext *s) avio_wl32(s->pb, count); // tag count // flags - avio_wl32(s->pb, APE_TAG_FLAG_CONTAINS_HEADER | APE_TAG_FLAG_CONTAINS_FOOTER); + avio_wl32(s->pb, APE_TAG_FLAG_CONTAINS_HEADER); ffio_fill(s->pb, 0, 8); // reserved // update values in the header From 4cc0227040adb9efc63be6a5765e3214f5c6f662 Mon Sep 17 00:00:00 2001 From: James Almer Date: Fri, 10 Feb 2017 20:24:27 -0300 Subject: [PATCH 2/2] apetag: account for header size if present when returning the start position The size field in the header/footer accounts for the entire APE tag structure except the 32 bytes from header, for compatibility with APEv1. Signed-off-by: James Almer CC: libav-stable@libav.org Signed-off-by: Anton Khirnov --- libavformat/apetag.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavformat/apetag.c b/libavformat/apetag.c index 93a4fb3430..a7cf8530f1 100644 --- a/libavformat/apetag.c +++ b/libavformat/apetag.c @@ -31,6 +31,7 @@ #define APE_TAG_VERSION 2000 #define APE_TAG_FOOTER_BYTES 32 +#define APE_TAG_HEADER_BYTES 32 #define APE_TAG_FLAG_CONTAINS_HEADER (1 << 31) #define APE_TAG_FLAG_LACKS_FOOTER (1 << 30) #define APE_TAG_FLAG_IS_HEADER (1 << 29) @@ -154,7 +155,6 @@ int64_t ff_ape_parse_tag(AVFormatContext *s) av_log(s, AV_LOG_ERROR, "Invalid tag size %"PRIu32".\n", tag_bytes); return 0; } - tag_start = file_size - tag_bytes - APE_TAG_FOOTER_BYTES; fields = avio_rl32(pb); /* number of fields */ if (fields > 65536) { @@ -170,6 +170,11 @@ int64_t ff_ape_parse_tag(AVFormatContext *s) avio_seek(pb, file_size - tag_bytes, SEEK_SET); + if (val & APE_TAG_FLAG_CONTAINS_HEADER) + tag_bytes += APE_TAG_HEADER_BYTES; + + tag_start = file_size - tag_bytes; + for (i=0; i