From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id BB8344D03B for ; Wed, 5 Nov 2025 19:38:04 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'jkNbHlDIktK8AQEGQxUwXnk+cqHOXhJzcgth3YClwRI=', expected b'ZQ24x8twU18yW4cdOwyN+275RSjVVg5xYblDL7x3Gb0=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1762371459; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=jkNbHlDIktK8AQEGQxUwXnk+cqHOXhJzcgth3YClwRI=; b=dbmOJc0mXpe+Dl+g4ZlSZcJZcFLRkKZWL/x2c75tDCfLdK84CeseTlZWwacCsKmleI+e1 gpBsdgHEDfPgNRYZExIF+qXFbuylF+O1AX0LSaQ7LcOrrzB3w5sR1AqSBQHpdPz+wBoV6Y6 PpBXwHDB/n4ywYUD+85fwTRythIT5UzmrZcxfKpPa3EPs7dJJwgy0Kul3JN4iCZ6Nl8oMQi jZDQ4K/vnmemsqDycy+rU3wEmddjYNAR1yRwonCQML5CUDG524JC2Jf4X0zSjOCbEvE5nSE uSyya6nt/j0NlydsOBtparLB5YanrM+l/R8QFIUt/DeMHHomCUO61bgmaNuw== Received: from [172.19.0.2] (unknown [172.19.0.2]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id B20F868FBB8; Wed, 5 Nov 2025 21:37:39 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1762371440; b=an5yFqzUstdw0j/QxtCJzFO5SqnRQlHu0bBPDYDhu/ZIx99S5ApzqeS7mSGw8EnCmmy1M dbBKmaPVZJBepksIhBQ84Vq4rs4xuTHf8vLOmBcPrLCB1a+VJMgJCi9swgzqK6l3ZUlkjmj escFwWXBJNeUyygbg9t4yujkHN2Y+pRviSW7BXe1yP5BVtUPCTHuI9UoTWpR+9JdeqZRXB4 t0s+ID4GVbQ2PPTGsKMkkW1k8omBBepMTQxHVUbtNv94rr3AUw7Km2ninINdIUM85jTOEgd P+/qqDyiQuil+CMdHsw5WkfuPd75PNLJb6xOGv3pqNM/ECU7JP4YLv0NFoiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1762371440; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=uBtWCWPO1gi8gP9OSn1AJdx5aZPkYr+TCzz54Tgd/kM=; b=TIjBP+G0cHS4FulnHL3pjNjZyW1UiX1XdOM+D5nmVb8jiNr3JzuKLGrkDqZAYIlZrcofg rNJpXMmlMQSvutK4f50pwUN3kW/NNnehTm+RFu1QJbDuU6I6Yrs3zKb+Xibj79XR8yK9CRE 8JBIFrxZ05Y6ShZ/IBc8Zr3cL47T5YJqvohJx9dCOnwvIlRrIN1yNEeIJz79VETf1k8svn7 Zkc+sBTo4exUR+0rxthzEwMkrk5O3jlr62z/QAQLp7L0RgjRO39BzJTbfX/XngEgNzoxoWy OrMraanB0QhJwC4QEqP9sef5ebZ1dBeDuQbbLPM0tDhPfjMLu7aVBvOcSDbg== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1762371433; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=ZQ24x8twU18yW4cdOwyN+275RSjVVg5xYblDL7x3Gb0=; b=x8OynMuUSvq++owjjxxuGCEwruyYZ+663hX7/9BDSfkyBWtx197Wz+maoIf8HI7tahRu4 sSfnMVTbuxIN5ZYGZyzTe+epsu6RX+gVjQmWyX7cfLukvQHGxiI1q7BEuXi4fEKTDrnDRQM SDr6jtBviepkvn7Q6MXsIzcqn3NwlegB2PVfMv/URqmMygCQUGJvTjMt1UXIZt2u5WawX8W LFMVTfOKiIkO/ESdoZ0Wou0PDGK2+gSNiNquU783py/MCrrvRT9bwfzT9+57xX2az7btthC uC1UVgbRcusp1BH6fdslohsdEXXDgasLlOapx/NiZuHb+YMW34iYTv/Pcujg== Received: from 188d6d40ca7a (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 184D368FABE for ; Wed, 5 Nov 2025 21:37:13 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Wed, 05 Nov 2025 19:37:12 -0000 Message-ID: <176237143329.25.11466857126401484102@2cb04c0e5124> Message-ID-Hash: 65ITLEYE33FLP3P4WWPYZNAEQ7IYLRK7 X-Message-ID-Hash: 65ITLEYE33FLP3P4WWPYZNAEQ7IYLRK7 X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] libavutil: add qtff well-known type functions (PR #20846) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Lukas via ffmpeg-devel Cc: Lukas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #20846 opened by Lukas (lholliger) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20846 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20846.patch QuickTime File Format (QTFF/MOV) have a list of well-known datatypes and there is currently little in place to decode or encode these values besides a small part in mov.c. This adds the ability to encode and decode various types for integers, floats, and strings. These well-known types have usage to decoding some parts on the moov atom or for metadata boxed/mebx values. Also updated mov.c to use this function. >>From 9a4c805ea90401f8c51f31be1c4c523815dfa100 Mon Sep 17 00:00:00 2001 From: lholliger Date: Wed, 5 Nov 2025 14:15:08 -0500 Subject: [PATCH 1/2] libavutil: add qtff well-known type functions QuickTime File Format (QTFF/MOV) have a list of well-known datatypes and there is currently little in place to decode or encode these values besides a small part in mov.c. This adds the ability to encode and decode various types for integers, floats, and strings. These well-known types have usage to decoding some parts on the moov atom or for metadata boxed/mebx values. Signed-off-by: lholliger --- libavutil/Makefile | 2 + libavutil/qtff.c | 380 +++++++++++++++++++++++++++++++++++++++++++++ libavutil/qtff.h | 59 +++++++ 3 files changed, 441 insertions(+) create mode 100644 libavutil/qtff.c create mode 100644 libavutil/qtff.h diff --git a/libavutil/Makefile b/libavutil/Makefile index ee77e51c08..792b587529 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -75,6 +75,7 @@ HEADERS = adler32.h \ pixdesc.h \ pixelutils.h \ pixfmt.h \ + qtff.h \ random_seed.h \ rc4.h \ rational.h \ @@ -168,6 +169,7 @@ OBJS = adler32.o \ parseutils.o \ pixdesc.o \ pixelutils.o \ + qtff.o \ random_seed.o \ rational.o \ refstruct.o \ diff --git a/libavutil/qtff.c b/libavutil/qtff.c new file mode 100644 index 0000000000..a58d360958 --- /dev/null +++ b/libavutil/qtff.c @@ -0,0 +1,380 @@ +/* + * copyright (c) 2025 Lukas Holliger + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include + +#include "qtff.h" +#include "intfloat.h" +#include "intreadwrite.h" +#include "error.h" + +int av_qtff_convert_well_known_to_str(int data_type, const uint8_t *data, int data_size, + char *str, int str_size) +{ + if (!data || !str || str_size <= 0) + return AVERROR(EINVAL); + + switch (data_type) { + case 0: // Reserved + case 2: // UTF-16 + case 3: // S/JIS + case 4: // UTF-8 sort + case 5: // UTF-16 sort + case 13: // JPEG + case 14: // PNG + case 27: // BMP + case 28: // QuickTime Metadata atom + case 70: // BE PointF32 + case 71: // BE DimensionsF32 + case 72: // BE RectF32 + case 79: // AffineTransformF64 + return AVERROR_PATCHWELCOME; + case 1: { // UTF-8 + int len = data_size < str_size - 1 ? data_size : str_size - 1; + memcpy(str, data, len); + str[len] = '\0'; + break; + } + case 21: { // BE Signed Integer (variable size, not usable for timed metadata) + int val = 0; + switch (data_size) { + case 1: + val = (int8_t)AV_RB8(data); + break; + case 2: + val = (int16_t)AV_RB16(data); + break; + case 3: + val = ((int32_t)(AV_RB24(data) << 8)) >> 8; + break; + case 4: + val = (int32_t)AV_RB32(data); + break; + default: + return AVERROR(EINVAL); + } + + if (snprintf(str, str_size, "%d", val) >= str_size) + return AVERROR(ENOMEM); + break; + } + case 22: { // BE Unsigned Integer (variable size, not usable for timed metadata) + unsigned int val = 0; + switch (data_size) { + case 1: + val = AV_RB8(data); + break; + case 2: + val = AV_RB16(data); + break; + case 3: + val = AV_RB24(data); + break; + case 4: + val = AV_RB32(data); + break; + default: + return AVERROR(EINVAL); + } + + if (snprintf(str, str_size, "%u", val) >= str_size) + return AVERROR(ENOMEM); + break; + } + case 23: { // BE float32 + float val; + if (data_size != 4) + return AVERROR(EINVAL); + + val = av_int2float(AV_RB32(data)); + if (snprintf(str, str_size, "%f", val) >= str_size) + return AVERROR(ENOMEM); + break; + } + case 24: { // BE float64 + double val; + if (data_size != 8) + return AVERROR(EINVAL); + + val = av_int2double(AV_RB64(data)); + if (snprintf(str, str_size, "%f", val) >= str_size) + return AVERROR(ENOMEM); + break; + } + case 65: // 8-bit Signed Integer + if (data_size != 1) + return AVERROR(EINVAL); + if (snprintf(str, str_size, "%d", (int)(int8_t)data[0]) >= str_size) + return AVERROR(ENOMEM); + break; + case 66: // BE 16-bit Signed Integer + if (data_size != 2) + return AVERROR(EINVAL); + if (snprintf(str, str_size, "%d", (int)(int16_t)AV_RB16(data)) >= str_size) + return AVERROR(ENOMEM); + break; + case 67: // BE 32-bit Signed Integer + if (data_size != 4) + return AVERROR(EINVAL); + if (snprintf(str, str_size, "%d", (int)(int32_t)AV_RB32(data)) >= str_size) + return AVERROR(ENOMEM); + break; + case 74: // BE 64-bit Signed Integer + if (data_size != 8) + return AVERROR(EINVAL); + if (snprintf(str, str_size, "%lld", (long long)(int64_t)AV_RB64(data)) >= str_size) + return AVERROR(ENOMEM); + break; + case 75: // 8-bit Unsigned Integer + if (data_size != 1) + return AVERROR(EINVAL); + if (snprintf(str, str_size, "%u", (unsigned int)data[0]) >= str_size) + return AVERROR(ENOMEM); + break; + case 76: // BE 16-bit Unsigned Integer + if (data_size != 2) + return AVERROR(EINVAL); + if (snprintf(str, str_size, "%u", (unsigned int)AV_RB16(data)) >= str_size) + return AVERROR(ENOMEM); + break; + case 77: // BE 32-bit Unsigned Integer + if (data_size != 4) + return AVERROR(EINVAL); + if (snprintf(str, str_size, "%u", (unsigned int)AV_RB32(data)) >= str_size) + return AVERROR(ENOMEM); + break; + case 78: // BE 64-bit Unsigned Integer + if (data_size != 8) + return AVERROR(EINVAL); + if (snprintf(str, str_size, "%llu", (unsigned long long)AV_RB64(data)) >= str_size) + return AVERROR(ENOMEM); + break; + default: + return AVERROR(EINVAL); + } + + return 0; +} + +int av_qtff_convert_str_to_well_known(int data_type, const char *str, uint8_t *data, int data_size) +{ + if (!str || !data) + return AVERROR(EINVAL); + + switch (data_type) { + case 0: // Reserved + case 2: // UTF-16 + case 3: // S/JIS + case 4: // UTF-8 sort + case 5: // UTF-16 sort + case 13: // JPEG + case 14: // PNG + case 27: // BMP + case 28: // QuickTime Metadata atom + case 70: // BE PointF32 + case 71: // BE DimensionsF32 + case 72: // BE RectF32 + case 79: // AffineTransformF64 + return AVERROR_PATCHWELCOME; // these are defined well-known types, but not implemented to be parsed + case 1: { // UTF-8 + int len = strlen(str); + if (len > data_size) + return AVERROR(ENOMEM); + memcpy(data, str, len); + return len; + } + case 21: { // BE Signed Integer (variable size, not usable for timed metadata) + long long val; + char *endptr; + + val = strtoll(str, &endptr, 10); + if (endptr == str || *endptr != '\0') + return AVERROR(EINVAL); + + switch (data_size) { + case 1: + if (val < INT8_MIN || val > INT8_MAX) + return AVERROR(ERANGE); + AV_WB8(data, (uint8_t)val); + break; + case 2: + if (val < INT16_MIN || val > INT16_MAX) + return AVERROR(ERANGE); + AV_WB16(data, (int16_t)val); + break; + case 3: + if (val < -8388608 || val > 8388607) // 24-bit signed range + return AVERROR(ERANGE); + AV_WB24(data, (int32_t)val); + break; + case 4: + if (val < INT32_MIN || val > INT32_MAX) + return AVERROR(ERANGE); + AV_WB32(data, (int32_t)val); + break; + default: + return AVERROR(EINVAL); + } + break; + } + case 22: { // BE unsigned integer, variable size + unsigned long long val; + char *endptr; + + val = strtoull(str, &endptr, 10); + if (endptr == str || *endptr != '\0') + return AVERROR(EINVAL); + + switch (data_size) { + case 1: + if (val > UINT8_MAX) + return AVERROR(ERANGE); + AV_WB8(data, (uint8_t)val); + break; + case 2: + if (val > UINT16_MAX) + return AVERROR(ERANGE); + AV_WB16(data, (uint16_t)val); + break; + case 3: + if (val > 16777215) // 24-bit unsigned range + return AVERROR(ERANGE); + AV_WB24(data, (uint32_t)val); + break; + case 4: + if (val > UINT32_MAX) + return AVERROR(ERANGE); + AV_WB32(data, (uint32_t)val); + break; + default: + return AVERROR(EINVAL); + } + break; + } + case 23: { // BE float32 + float val; + char *endptr; + + if (data_size != 4) + return AVERROR(EINVAL); + + val = strtof(str, &endptr); + if (endptr == str || *endptr != '\0') + return AVERROR(EINVAL); + + AV_WB32(data, av_float2int(val)); + break; + } + case 24: { // BE float64 + double val; + char *endptr; + + if (data_size != 8) + return AVERROR(EINVAL); + + val = strtod(str, &endptr); + if (endptr == str || *endptr != '\0') + return AVERROR(EINVAL); + + AV_WB64(data, av_double2int(val)); + break; + } + case 65: // 8-bit Signed Integer + case 66: // BE 16-bit Signed Integer + case 67: // BE 32-bit Signed Integer + case 74: { // BE 64-bit Signed Integer + long long val; + char *endptr; + int expected_size = (data_type == 65) ? 1 : (data_type == 66) ? 2 : (data_type == 67) ? 4 : 8; + + if (data_size != expected_size) + return AVERROR(EINVAL); + + val = strtoll(str, &endptr, 10); + if (endptr == str || *endptr != '\0') + return AVERROR(EINVAL); + + switch (data_type) { + case 65: + if (val < INT8_MIN || val > INT8_MAX) + return AVERROR(ERANGE); + AV_WB8(data, (uint8_t)val); + break; + case 66: + if (val < INT16_MIN || val > INT16_MAX) + return AVERROR(ERANGE); + AV_WB16(data, (int16_t)val); + break; + case 67: + if (val < INT32_MIN || val > INT32_MAX) + return AVERROR(ERANGE); + AV_WB32(data, (int32_t)val); + break; + case 74: + AV_WB64(data, (int64_t)val); + break; + } + break; + } + case 75: // 8-bit Unsigned Integer + case 76: // BE 16-bit Unsigned Integer + case 77: // BE 32-bit Unsigned Integer + case 78: { // BE 64-bit Unsigned Integer + unsigned long long val; + char *endptr; + int expected_size = (data_type == 75) ? 1 : (data_type == 76) ? 2 : (data_type == 77) ? 4 : 8; + + if (data_size != expected_size) + return AVERROR(EINVAL); + + val = strtoull(str, &endptr, 10); + if (endptr == str || *endptr != '\0') + return AVERROR(EINVAL); + + switch (data_type) { + case 75: + if (val > UINT8_MAX) + return AVERROR(ERANGE); + AV_WB8(data, (uint8_t)val); + break; + case 76: + if (val > UINT16_MAX) + return AVERROR(ERANGE); + AV_WB16(data, (uint16_t)val); + break; + case 77: + if (val > UINT32_MAX) + return AVERROR(ERANGE); + AV_WB32(data, (uint32_t)val); + break; + case 78: + AV_WB64(data, (uint64_t)val); + break; + } + break; + } + default: + return AVERROR(EINVAL); + } + + return data_size; +} diff --git a/libavutil/qtff.h b/libavutil/qtff.h new file mode 100644 index 0000000000..912ea9e870 --- /dev/null +++ b/libavutil/qtff.h @@ -0,0 +1,59 @@ +/* + * copyright (c) 2025 Lukas Holliger + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_QTFF_H +#define AVUTIL_QTFF_H + +#include + +/** + * @file + * QuickTime File Format (QTFF) utilities + */ + +/** + * Convert a QuickTime well-known type to a string + * + * @param data_type QuickTime metadata data type + * @param data Pointer to the binary data + * @param data_size Size of the binary data in bytes + * @param str Buffer to write the string representation to + * @param str_size Size of the output buffer + * @return 0 on success, negative AVERROR code on failure + * + * @see https://developer.apple.com/documentation/quicktime-file-format/well-known_types + */ +int av_qtff_convert_well_known_to_str(int data_type, const uint8_t *data, int data_size, + char *str, int str_size); + +/** + * Convert a string to QuickTime well-known value + * + * @param data_type QuickTime metadata data type + * @param str Input string to convert + * @param data Buffer to write the binary data to + * @param data_size Size to use for the binary data + * @return Number of bytes written on success, negative AVERROR code on failure + * + * @see https://developer.apple.com/documentation/quicktime-file-format/well-known_types + */ +int av_qtff_convert_str_to_well_known(int data_type, const char *str, uint8_t *data, int data_size); + +#endif /* AVUTIL_QTFF_H */ -- 2.49.1 >>From 3616592b585440ca4984052e53c85ff5df29f3bf Mon Sep 17 00:00:00 2001 From: lholliger Date: Wed, 5 Nov 2025 14:33:22 -0500 Subject: [PATCH 2/2] libavformat/mov: use qtff decoder util There was previously a segment here to attempt to decode some of the well-known QTFF types but in order to simplify the function and implement more types this segment can be replaced with a call to the qtff util. Signed-off-by: lholliger --- libavformat/mov.c | 78 +++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 50 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 45c562cdc6..9cf62955c2 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -45,6 +45,7 @@ #include "libavutil/aes.h" #include "libavutil/aes_ctr.h" #include "libavutil/pixdesc.h" +#include "libavutil/qtff.h" #include "libavutil/sha.h" #include "libavutil/spherical.h" #include "libavutil/stereo3d.h" @@ -521,61 +522,38 @@ retry: else { if (!raw && (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff)))) { // MAC Encoded mov_read_mac_string(c, pb, str_size, str, str_size_alloc); - } else if (data_type == 21) { // BE signed integer, variable size - int val = 0; - if (str_size == 1) - val = (int8_t)avio_r8(pb); - else if (str_size == 2) - val = (int16_t)avio_rb16(pb); - else if (str_size == 3) - val = ((int32_t)(avio_rb24(pb)<<8))>>8; - else if (str_size == 4) - val = (int32_t)avio_rb32(pb); - if (snprintf(str, str_size_alloc, "%d", val) >= str_size_alloc) { - av_log(c->fc, AV_LOG_ERROR, - "Failed to store the number (%d) in string.\n", val); - av_free(str); - return AVERROR_INVALIDDATA; - } - } else if (data_type == 22) { // BE unsigned integer, variable size - unsigned int val = 0; - if (str_size == 1) - val = avio_r8(pb); - else if (str_size == 2) - val = avio_rb16(pb); - else if (str_size == 3) - val = avio_rb24(pb); - else if (str_size == 4) - val = avio_rb32(pb); - if (snprintf(str, str_size_alloc, "%u", val) >= str_size_alloc) { - av_log(c->fc, AV_LOG_ERROR, - "Failed to store the number (%u) in string.\n", val); - av_free(str); - return AVERROR_INVALIDDATA; - } - } else if (data_type == 23 && str_size >= 4) { // BE float32 - float val = av_int2float(avio_rb32(pb)); - if (snprintf(str, str_size_alloc, "%f", val) >= str_size_alloc) { - av_log(c->fc, AV_LOG_ERROR, - "Failed to store the float32 number (%f) in string.\n", val); - av_free(str); - return AVERROR_INVALIDDATA; - } - } else if (data_type > 1 && data_type != 4) { - // data_type can be 0 if not set at all above. data_type 1 means - // UTF8 and 4 means "UTF8 sort". For any other type (UTF16 or e.g. - // a picture), don't return it blindly in a string that is supposed - // to be UTF8 text. - av_log(c->fc, AV_LOG_WARNING, "Skipping unhandled metadata %s of type %d\n", key, data_type); - av_free(str); - return 0; } else { - int ret = ffio_read_size(pb, str, str_size); + uint8_t *data_buf = av_malloc(str_size); + int ret; + + if (!data_buf) { + av_free(str); + return AVERROR(ENOMEM); + } + + ret = ffio_read_size(pb, data_buf, str_size); if (ret < 0) { + av_free(data_buf); + av_free(str); + return ret; + } + + // Data types 0 and 4 are technically reserved and a special case, but were previously + // decoded to UTF-8 here. + ret = av_qtff_convert_well_known_to_str(data_type == 0 || data_type == 4 ? 1 : data_type, + data_buf, str_size, str, str_size_alloc); + av_free(data_buf); + + if (ret == AVERROR_PATCHWELCOME || ret == AVERROR(EINVAL)) { + av_log(c->fc, AV_LOG_WARNING, "Skipping unhandled metadata %s of type %d\n", key, data_type); + av_free(str); + return 0; + } else if (ret < 0) { + av_log(c->fc, AV_LOG_ERROR, + "Failed to convert metadata %s of type %d to string.\n", key, data_type); av_free(str); return ret; } - str[str_size] = 0; } c->fc->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED; av_dict_set(metadata, key, str, 0); -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org