Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

InflaterInputStream doesn't reset position of underlying stream to end of deflated data

未关闭
#584 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
csharp
领域
backend

调研方向

从 InflaterInputStream 及其 Read 入口开始,然后使用包含尾随数据的文件重现该示例,以观察底层流的位置如何变化。完成的标准是:解压后,底层流位于压缩数据的末尾,因此后续读取 4 个字节时返回的是尾随数据,而不是缓冲的字节。

由索引模型根据 Issue 内容生成。

描述

Steps to reproduce
  1. Obtain a file that contains a deflated blob with some other data following it. In my case, I have a binary file where there is a deflated blob, followed by some additional ints/floats/etc. It's important that there is trailing data after the deflated blob. It doesn't matter what the data is, it could be garbage. It just has to exist. The code below assumes there is at least 4 bytes in this trailing data.
  2. Run this simple program against it, after filling in appropriate values for InFile, InFileCompressedDataStartPos, InFileCompressedLength, and InFileUncompressedLength:
    internal class Program
    {
        private static string InFile = @"";

        private static int InFileCompressedDataStart = 0;
        private static int InFileCompressedLength = 0;
        private static int InFileUncompressedLength = 0;
        
        public static void Main(string[] args)
        {
            using (var stream = File.OpenRead(InFile))
            {
                stream.Position = InFileCompressedDataStart;

                //Encounter deflated blob in stream, and inflate it
                using (var zStream = new InflaterInputStream(stream))
                {
                    zStream.IsStreamOwner = false;
                    var buffer = new byte[InFileUncompressedLength];

                    var streamStartPos = stream.Position;
                    Console.WriteLine($"Stream position before inflate: {streamStartPos}");

                    var read = zStream.Read(buffer, 0, InFileCompressedLength);
                    Console.WriteLine($"InflaterInputStream read {read} bytes");

                    var streamEndPos = stream.Position;
                    Console.WriteLine($"Stream position after inflate: {streamEndPos}");
                    Console.WriteLine($"Stream position moved {streamEndPos - streamStartPos} bytes during read");
                }

                //Continue on with data following deflated blob
                var testBuffer = new byte[4];
                stream.Read(testBuffer, 0, 4);    //This reads from the wrong offset in the file!
            }
        }
    }
  1. Note the console output
Expected behavior

stream.Position should have progressed by InFileCompressedLength. (to allow the trailing data to be read independently)

Actual behavior

stream.Position progressed by some amount greater than InFileCompressedLength. (this is part way thru completely unrelated data!)

Version of SharpZipLib

1.3.1

Obtained from (only keep the relevant lines)
  • Package installed using NuGet
主要语言
C#
星标
3.9k
派生
1k
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

icsharpcode/SharpZipLib 的其他 Issue

查看 icsharpcode/SharpZipLib 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。