From: softworkz <ffmpegagent@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: softworkz <softworkz@hotmail.com> Subject: [FFmpeg-devel] [PATCH v2 2/2] fftools/resman: uncompress to actual-size memory buffers Date: Sat, 31 May 2025 03:58:45 +0000 Message-ID: <32cd61ebd4196f09ca2ed1d1c062ac2370844f75.1748663925.git.ffmpegagent@gmail.com> (raw) In-Reply-To: <pull.90.v2.ffstaging.FFmpeg.1748663925.ffmpegagent@gmail.com> From: softworkz <softworkz@hotmail.com> Signed-off-by: softworkz <softworkz@hotmail.com> --- fftools/resources/resman.c | 51 +++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/fftools/resources/resman.c b/fftools/resources/resman.c index f098bd6687..e3e082abbf 100644 --- a/fftools/resources/resman.c +++ b/fftools/resources/resman.c @@ -67,48 +67,69 @@ 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_mallocz(uncompressed_size + 1); if (!buf) { av_log(ctx, AV_LOG_ERROR, "Failed to allocate decompression buffer\n"); + inflateEnd(&strm); return AVERROR(ENOMEM); } - // 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.avail_out = uncompressed_size; strm.next_out = buf; 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); + 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); + 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"); - } + av_assert0(strm.avail_out == 0); - *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".
prev parent reply other threads:[~2025-05-31 3:59 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-05-31 1:50 [FFmpeg-devel] [PATCH 0/2] fftools/resman: remove redundant includes, use inflate loop ffmpegagent 2025-05-31 1:50 ` [FFmpeg-devel] [PATCH 1/2] fftools/resman: remove unused includes, fix declaration softworkz 2025-05-31 1:50 ` [FFmpeg-devel] [PATCH 2/2] fftools/resman: use inflate loop with increasing buffer size softworkz 2025-05-31 2:38 ` Kieran Kunhya via ffmpeg-devel 2025-05-31 2:45 ` softworkz . 2025-05-31 3:57 ` softworkz . 2025-05-31 3:58 ` [FFmpeg-devel] [PATCH v2 0/2] fftools/resman: remove redundant includes, use inflate loop ffmpegagent 2025-05-31 3:58 ` [FFmpeg-devel] [PATCH v2 1/2] fftools/resman: remove unused includes, fix declaration softworkz 2025-06-02 1:28 ` Michael Niedermayer 2025-06-02 1:42 ` softworkz . 2025-06-02 3:28 ` softworkz . 2025-05-31 3:58 ` softworkz [this message]
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=32cd61ebd4196f09ca2ed1d1c062ac2370844f75.1748663925.git.ffmpegagent@gmail.com \ --to=ffmpegagent@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ --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