From: ffmpegagent <ffmpegagent@gmail.com> To: ffmpegdev@gitmailbox.com Cc: softworkz <softworkz@hotmail.com>, softworkz <softworkz@hotmail.com> Subject: [PATCH 04/11] libavformat/asfdec: fixing get_tag Date: Wed, 22 Dec 2021 14:33:00 +0000 Message-ID: <8fa3a58039f6ee66a2fa3a69cbd688d10824990c.1640183587.git.ffmpegagent@gmail.com> (raw) In-Reply-To: <pull.11.ffstaging.FFmpeg.1640183587.ffmpegagent@gmail.com> From: softworkz <softworkz@hotmail.com> These three are closely related and can't be separated easily: In get_tag, the code was adding 22 bytes (in order to allow it to hold 64bit numbers as string) to the value len for creating creating a buffer. This was unnecessarily imposing a size-constraint on the value_len parameter. The code in get_tag, was limiting the maximum value_len to half the size of INT32. This was applied for all value types, even though it is required only in case of ASF_UNICODE, not for any other ones (like ASCII). get_tag was always allocating a buffer regardless of the datatype, even though this isn't required in case of ASF_BYTE_ARRAY The check for the return value from ff_asf_handle_byte_array() being >0 is removed here because the log message is emitted by the function itself now. Signed-off-by: softworkz <softworkz@hotmail.com> --- libavformat/asfdec_f.c | 54 +++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c index 29b429fee9..58c424b565 100644 --- a/libavformat/asfdec_f.c +++ b/libavformat/asfdec_f.c @@ -221,37 +221,63 @@ static uint64_t get_value(AVIOContext *pb, int type, int type2_size) static void get_tag(AVFormatContext *s, const char *key, int type, uint32_t len, int type2_size) { ASFContext *asf = s->priv_data; - char *value = NULL; int64_t off = avio_tell(s->pb); -#define LEN 22 - - av_assert0((unsigned)len < (INT_MAX - LEN) / 2); + char *value = NULL; + uint64_t required_bufferlen; + int buffer_len; if (!asf->export_xmp && !strncmp(key, "xmp", 3)) goto finish; - value = av_malloc(2 * len + LEN); + switch (type) { + case ASF_UNICODE: + required_bufferlen = (uint64_t)len * 2 + 1; + break; + case -1: // ASCII + required_bufferlen = (uint64_t)len + 1; + break; + case ASF_BYTE_ARRAY: + ff_asf_handle_byte_array(s, key, len); + goto finish; + case ASF_BOOL: + case ASF_DWORD: + case ASF_QWORD: + case ASF_WORD: + required_bufferlen = 22; + break; + case ASF_GUID: + required_bufferlen = 33; + break; + default: + required_bufferlen = len; + break; + } + + if (required_bufferlen > INT32_MAX) { + av_log(s, AV_LOG_VERBOSE, "Unable to handle values > INT32_MAX in tag %s.\n", key); + goto finish; + } + + buffer_len = (int)required_bufferlen; + + value = av_malloc(buffer_len); if (!value) goto finish; switch (type) { case ASF_UNICODE: - avio_get_str16le(s->pb, len, value, 2 * len + 1); + avio_get_str16le(s->pb, len, value, buffer_len); break; - case -1: // ASCI - avio_read(s->pb, value, len); - value[len]=0; + case -1: // ASCII + avio_read(s->pb, value, buffer_len - 1); + value[buffer_len - 1] = 0; break; - case ASF_BYTE_ARRAY: - if (ff_asf_handle_byte_array(s, key, len) > 0) - av_log(s, AV_LOG_VERBOSE, "Unsupported byte array in tag %s.\n", key); - goto finish; case ASF_BOOL: case ASF_DWORD: case ASF_QWORD: case ASF_WORD: { uint64_t num = get_value(s->pb, type, type2_size); - snprintf(value, LEN, "%"PRIu64, num); + snprintf(value, buffer_len, "%"PRIu64, num); break; } case ASF_GUID: -- gitgitgadget
next prev parent reply other threads:[~2021-12-22 15:27 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-12-22 14:32 [PATCH 00/11] libavformat/asfdec: Fix variable types and add checks for unsupported values ffmpegagent 2021-12-22 14:32 ` [PATCH 01/11] libavformat/asf: fix handling of byte array length values ffmpegagent 2021-12-22 15:24 ` Soft Works 2021-12-22 14:32 ` [PATCH 02/11] libavformat/asfdec: fix get_value return type and add checks for ffmpegagent 2021-12-22 14:32 ` [PATCH 03/11] libavformat/asfdec: fix type of value_len ffmpegagent 2021-12-22 14:33 ` ffmpegagent [this message] 2021-12-22 14:33 ` [PATCH 05/11] libavformat/asfdec: implement parsing of GUID values ffmpegagent 2021-12-22 14:33 ` [PATCH 06/11] libavformat/asfdec: remove unused parameters ffmpegagent 2021-12-22 14:33 ` [PATCH 07/11] libavformat/asfdec: fix macro definition and use ffmpegagent 2021-12-22 14:33 ` [PATCH 08/11] libavformat/asfdec: remove variable redefinition in inner scope ffmpegagent 2021-12-22 14:33 ` [PATCH 09/11] libavformat/asfdec: ensure variables are initialized ffmpegagent 2021-12-22 14:33 ` [PATCH 10/11] libavformat/asfdec: fix parameter type in asf_read_stream_propertie() ffmpegagent 2021-12-22 14:33 ` [PATCH 11/11] libavformat/asfdec: fix variable types and add checks for unsupported values ffmpegagent 2021-12-22 15:13 [PATCH 00/11] libavformat/asf: fix handling of byte array length values ffmpegagent 2021-12-22 15:13 ` [PATCH 04/11] libavformat/asfdec: fixing get_tag ffmpegagent
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=8fa3a58039f6ee66a2fa3a69cbd688d10824990c.1640183587.git.ffmpegagent@gmail.com \ --to=ffmpegagent@gmail.com \ --cc=ffmpegdev@gitmailbox.com \ --cc=softworkz@hotmail.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git