Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zlib.managed stuck on unpack #181

Open
Bargest opened this issue May 18, 2023 · 0 comments
Open

zlib.managed stuck on unpack #181

Bargest opened this issue May 18, 2023 · 0 comments

Comments

@Bargest
Copy link

Bargest commented May 18, 2023

Describe the bug
zlib.managed gets stuck in infinite loop on unpacking certain files. Test file is attached. It can be unpacked with zlib.net with no issues.
The deepest call in this loop is Inflate_flush under

zlib.managed.dll!Elskom.Generic.Libs.InfCodes.Proc(Elskom.Generic.Libs.InfBlocks s, Elskom.Generic.Libs.ZlibStream z, Elskom.Generic.Libs.ZlibCompressionState r) Line 398
zlib.managed.dll!Elskom.Generic.Libs.InfBlocks.Proc(Elskom.Generic.Libs.ZlibStream z, Elskom.Generic.Libs.ZlibCompressionState r) Line 565
zlib.managed.dll!Elskom.Generic.Libs.Inflate.Decompress(Elskom.Generic.Libs.ZlibStream z, Elskom.Generic.Libs.ZlibFlushStrategy f) Line 166
zlib.managed.dll!Elskom.Generic.Libs.ZlibStream.Inflate(Elskom.Generic.Libs.ZlibFlushStrategy f) Line 355
zlib.managed.dll!Elskom.Generic.Libs.ZlibStream.Read(byte[] buffer, int offset, int count) Line 175

The problem is Inflate_flush gets this.Read equal this.Write, though q is less than this.End, which makes n to be 0. Nothing is flushed to output with Array.Copy, state does not change, return value is Ok, so on the next iteration we run into exactly the same path.

To Reproduce
Unpack test file from attached zip and run

using (var fsi = File.OpenRead(@"path\to\file.zlib"))
using (var fso = File.OpenWrite(@"path\to\file_unp"))
using (var zlib = new Elskom.Generic.Libs.ZlibStream(fsi, true))
	zlib.CopyTo(fso);

Expected behavior
File is unpacked successfully

Actual behavior
Code is stuck in infinite loop

Version used
main branch (d1fa75f)
file.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant