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 0D2034D287 for ; Sat, 31 May 2025 03:59:00 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id C866C68DBAC; Sat, 31 May 2025 06:58:58 +0300 (EEST) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id C556168CC79 for ; Sat, 31 May 2025 06:58:52 +0300 (EEST) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2345c60507bso18019655ad.0 for ; Fri, 30 May 2025 20:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748663931; x=1749268731; darn=ffmpeg.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Vdt2nmBSOD6o8Lmpy2qMT3umL2RD5naHWOMYPqflFaI=; b=cSdKg+g6Q+7h6fPtDGaA0UUQr+cUR+vJRUaCFELligMXBfNKPrLEwx/GPyulpSMCIT Jt9b8DqoRXgAPGLkkSh5h7tUR2ayPMcVD2mFKyC0XxECOHZWepYFT48GHkvqDtoSEo/z tTcId5XUTGQl6O9WIWRWsj8HnFxuUfi95Dkg4NN0bIcUGtFj7odGc4SbMW6+H5Q9M0Da ZDryMHoAGug6fIE2DdvdSyOOTFl+Xldg85KS+0UhafGbf4jmP9NGjEXem22KaNOkfkut McQiQQWgU7O4Ib+awVB5I9KobAFD/Twwi91l8RtvvLiPCoSURh2VY69FiDOSWM1AU071 bhUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748663931; x=1749268731; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vdt2nmBSOD6o8Lmpy2qMT3umL2RD5naHWOMYPqflFaI=; b=EfbB4fYuwj7/kLJMt6SCimXzYPEJ8KEKro7Tv69G96x9EUJRvweZJ9xJc9INPT9yNa wNzfm7oLM2YtD5NNIu4FRGnSH+knEL0aPwmIl89KXIrrEW4IoruqkaoZGSjOtAEOZUfT YWyl1UjOCVRfHTKHztP20xO3nlTVvhHXdTdtzgmph6v17C95ee+gq84K1F7Isw5djTMh /AJQ4Dlk32bPl9Xwomhel9D2LGmCZ3kApgnKTcHeTQjT18z7vtot1bhZAmFIKx2nkj6x HtDB8Zg1xnOsWQepvGRCP5IZryy/ha7ywDfGN3KxIpspN/o5wep82ZAHoO0xKABjgZYy rM8A== X-Gm-Message-State: AOJu0YzqiBRjlMrn1WZ9AnFWWxj3GJOK7yps+ynRVkJNinl2Qa01BbE4 /BzzoCx1JvOFMU7RHrNKIQX0O87W1D7LWkCJ+1wL6udgj9PHkF+7bQb1kME7Gw== X-Gm-Gg: ASbGncuzAJu8m2jjMa7kZmDt4pJxSof+pyjvu7PJcvft010VtAxjMLo8dGTFcFtrNBi Yy7Nn+DgZqzWNoRGYx0rgVzqX+kVkqbypgGN23IwIYyg8tlfxje4EjV6xuOxt3MxdL2wmwU9FHN WsyVZKTK2LnWXlvAQpsq50gBRNmv4H3itE8MImb/bnziGrY8V+Thdz3HjCBbxyv0/gLGCcDOwlR ezGc1tHQhV9GArQbgDFmfHsKAge5KgWfDZ3fSEEiX1Cide3bhtoxzI/gTulnruR3XxGgUZCJrva kReewjRERsx45iebTC910+R94bYh554cSL7BFj+zysVGDHyjYd6UlJgjyhqK1lw4NhGr7LU0bUP zo5u7YGN1XJj1QnU= X-Google-Smtp-Source: AGHT+IFtrM6WBjuD5RqW/xKi4feqgzRjj1PyqPqQI1f5liFbJQz3QhoTcwFN3KEwnadcJq7XOQR0dg== X-Received: by 2002:a17:902:f70e:b0:234:8c64:7875 with SMTP id d9443c01a7336-2355f76c34emr10739135ad.38.1748663930795; Fri, 30 May 2025 20:58:50 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23506bc8657sm35426065ad.30.2025.05.30.20.58.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 May 2025 20:58:50 -0700 (PDT) Message-Id: In-Reply-To: References: From: ffmpegagent Date: Sat, 31 May 2025 03:58:43 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2 0/2] fftools/resman: remove redundant includes, use inflate loop 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: and other cosmetic fixes. As per review by Ramiro Polla in message: "Re: [FFmpeg-devel] [FFmpeg-cvslog] fftools/resources: Add resource manager files with build-time compression" V2 * Use two-pass decompression to return resources in actual-size memory buffers (in response to comment by Kieran) . softworkz (2): fftools/resman: remove unused includes, fix declaration fftools/resman: uncompress to actual-size memory buffers fftools/resources/resman.c | 56 ++++++++++++++++++++++++++------------ fftools/resources/resman.h | 10 +------ 2 files changed, 39 insertions(+), 27 deletions(-) base-commit: 27c5e4b39afb272638ab907a710e7db4f867266d Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-90%2Fsoftworkz%2Fsubmit_resman_fixes-v2 Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-90/softworkz/submit_resman_fixes-v2 Pull-Request: https://github.com/ffstaging/FFmpeg/pull/90 Range-diff vs v1: 1: 4d7af186ce = 1: 4d7af186ce fftools/resman: remove unused includes, fix declaration 2: 48fc3a6810 ! 2: 32cd61ebd4 fftools/resman: use inflate loop with increasing buffer size @@ Metadata Author: softworkz ## Commit message ## - fftools/resman: use inflate loop with increasing buffer size + fftools/resman: uncompress to actual-size memory buffers Signed-off-by: softworkz ## fftools/resources/resman.c ## -@@ fftools/resources/resman.c: static int decompress_gzip(ResourceManagerContext *ctx, uint8_t *in, unsigned in - memset(&strm, 0, sizeof(strm)); +@@ fftools/resources/resman.c: static ResourceManagerContext *resman_ctx = NULL; + + static int decompress_gzip(ResourceManagerContext *ctx, uint8_t *in, unsigned in_len, char **out, size_t *out_len) + { +- z_stream strm; +- unsigned chunk = 65534; ++ z_stream strm = { 0 }; ++ uint8_t dummy[4096]; ++ size_t uncompressed_size; + int ret; + uint8_t *buf; + + *out = NULL; +- memset(&strm, 0, sizeof(strm)); ++ ++ // 15 + 16 tells zlib to detect GZIP or zlib automatically ++ ret = inflateInit2(&strm, 15 + 16); ++ if (ret != Z_OK) { ++ av_log(ctx, AV_LOG_ERROR, "Error during zlib initialization: %s\n", strm.msg); ++ return AVERROR(ENOSYS); ++ } ++ ++ strm.avail_in = in_len; ++ strm.next_in = in; ++ ++ do { ++ strm.avail_out = sizeof(dummy); ++ strm.next_out = dummy; ++ ++ ret = inflate(&strm, Z_NO_FLUSH); ++ if (ret != Z_OK && ret != Z_STREAM_END) { ++ av_log(ctx, AV_LOG_ERROR, "Inflate failed (1): %d, %s\n", ret, strm.msg); ++ inflateEnd(&strm); ++ return AVERROR(EINVAL); ++ } ++ } while (ret != Z_STREAM_END); ++ ++ uncompressed_size = strm.total_out; // Allocate output buffer with extra byte for null termination - buf = av_mallocz(chunk + 1); -+ buf = av_realloc(NULL, chunk + 1); ++ buf = av_mallocz(uncompressed_size + 1); if (!buf) { av_log(ctx, AV_LOG_ERROR, "Failed to allocate decompression buffer\n"); ++ inflateEnd(&strm); return AVERROR(ENOMEM); -@@ fftools/resources/resman.c: static int decompress_gzip(ResourceManagerContext *ctx, uint8_t *in, unsigned in + } + +- // 15 + 16 tells zlib to detect GZIP or zlib automatically +- ret = inflateInit2(&strm, 15 + 16); ++ ret = inflateReset(&strm); + if (ret != Z_OK) { +- av_log(ctx, AV_LOG_ERROR, "Error during zlib initialization: %s\n", strm.msg); ++ av_log(ctx, AV_LOG_ERROR, "inflateReset failed: %s\n", strm.msg); + av_free(buf); + return AVERROR(ENOSYS); + } strm.avail_in = in_len; strm.next_in = in; - strm.avail_out = chunk; -- strm.next_out = buf; ++ strm.avail_out = uncompressed_size; + strm.next_out = buf; -- ret = inflate(&strm, Z_FINISH); -- if (ret != Z_OK && ret != Z_STREAM_END) { + ret = inflate(&strm, Z_FINISH); + if (ret != Z_OK && ret != Z_STREAM_END) { - av_log(ctx, AV_LOG_ERROR, "Inflate failed: %d, %s\n", ret, strm.msg); -- inflateEnd(&strm); -- av_free(buf); ++ av_log(ctx, AV_LOG_ERROR, "Inflate failed (2): %d, %s\n", ret, strm.msg); + inflateEnd(&strm); + av_free(buf); - return (ret == Z_STREAM_END) ? Z_OK : ((ret == Z_OK) ? Z_BUF_ERROR : ret); -- } -+ do { -+ strm.avail_out = chunk - strm.total_out; -+ strm.next_out = buf + strm.total_out; ++ return AVERROR(EINVAL); + } - if (strm.avail_out == 0) { - // TODO: Error or loop decoding? - av_log(ctx, AV_LOG_WARNING, "Decompression buffer may be too small\n"); - } -+ ret = inflate(&strm, Z_FINISH); -+ if (ret != Z_OK && ret != Z_STREAM_END && ret != Z_BUF_ERROR) { -+ av_log(ctx, AV_LOG_ERROR, "Inflate failed: %d, %s\n", ret, strm.msg); -+ inflateEnd(&strm); -+ av_free(buf); -+ return AVERROR(EINVAL); -+ } -+ -+ if (strm.avail_out == 0) { -+ chunk *= 8; -+ uint8_t *tmp_buf = av_realloc(buf, chunk + 1); -+ if (!tmp_buf) { -+ inflateEnd(&strm); -+ av_free(buf); -+ return AVERROR(ENOMEM); -+ } -+ -+ buf = tmp_buf; -+ } -+ } while (ret != Z_STREAM_END); ++ av_assert0(strm.avail_out == 0); - *out_len = chunk - strm.avail_out; +- *out_len = chunk - strm.avail_out; ++ *out_len = uncompressed_size; buf[*out_len] = 0; // Ensure null termination + + inflateEnd(&strm); -- 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".