From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 1B65742933 for ; Sat, 7 May 2022 09:37:36 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BE54268B377; Sat, 7 May 2022 12:37:00 +0300 (EEST) Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 95D7368B39C for ; Sat, 7 May 2022 12:36:52 +0300 (EEST) Received: by mail-pj1-f54.google.com with SMTP id p6so9075869pjm.1 for ; Sat, 07 May 2022 02:36:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=uSQDD2TlyDjUamOqi0GwFXYuJYMq6guSKs/Ag8745es=; b=T18XCfRfr05cXX9WMykZi5dIf8jjyBYgLJmSzJAOEMIJ6haVdPjZZE7EPEzAjw4Xrp yXurIaNLrMRbdqUjwX1iwbVllC4iY8ZUkxeYmzIrKRiGRVuMtAhyyCZjDooKbNZu69PD 6gFu7t4lsQQaITGSY/SvOCtRQCAPcXsju1BrpKiY7guumdP48YoYi/BoPkKVp6ZDNN39 lAQkY9FfNID3UFm5ipMRY3Q90lUUMOk2svE6PEnbAKLZxUJke/ajgbRI6b4RG85WEIq5 9HI4ZorZOFE9e6URasT1l5gc6bo3qBpBCtDmaDwJqJxxCOSMiutxxKQyfTNtaFh9zqY8 0ulg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=uSQDD2TlyDjUamOqi0GwFXYuJYMq6guSKs/Ag8745es=; b=jBEcXaWS1G8CHlKNAnNV7u3Z2P0W4ak6CeLCSsbtMVNUCg/QOFZddGZaBUQnzBGyXQ BMD8xjBbH3wyYWDp4rJr9hVhD2c6Ev2FjooL0OjcVD1iYr1Z9RwnYJqKpJChLRjjux6y f6Ow40O7uafyg9dqjz7vxzXZdGZd15lq77D5FG01sNHNTDO4ieO8JMZgjPp+tZHyKL9O IGEXIN4k7gtGH/NEvA8KmTaKgb5aXnE1g8FQuGglXXcW/0qVqAo4NYuSARHV5sEW1Q4d f/U1SjOpIxG6HHNoPd9q0yO1X6Fq3Iz2Zc//s+Ocw7meI6xmr3fBG25zW0nlneHvTiK7 zqaQ== X-Gm-Message-State: AOAM530AVG0WBBo6yVWLJW4hQUGtys0zxEkIw7ryBxkl/BztHjsDbyLm 27dfeE0hZHXbjPk7Zneg43XbixqSrIIn2A== X-Google-Smtp-Source: ABdhPJxcbmhgtkl3OZ7M+1RTjp9bS7VLLSCKHfEpnbPPa67WH6A3wIey1b1khds7pY+iclcybxPFkQ== X-Received: by 2002:a17:90a:4898:b0:1d9:50aa:2a62 with SMTP id b24-20020a17090a489800b001d950aa2a62mr8795315pjh.115.1651916211050; Sat, 07 May 2022 02:36:51 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id r15-20020a65498f000000b003c14af50616sm4835513pgs.46.2022.05.07.02.36.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 May 2022 02:36:50 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <6e19df6e89bf0505b0ec98b0e95046892cd89d2b.1651916204.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Sat, 07 May 2022 09:36:37 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2 04/11] libavformat/asfdec: fixing get_tag X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: softworkz Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: softworkz 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 --- 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: -- ffmpeg-codebot _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".