madler / zlib

A massively spiffy yet delicately unobtrusive compression library.
http://zlib.net/
Other
5.58k stars 2.43k forks source link

Don't fail in gz_load() if read would block #993

Open drbitboy opened 1 month ago

drbitboy commented 1 month ago

I.e. when [errno] is EAGAIN or EWOULDBLOCK)

E.g. if file descriptor is a non-blocking TCP socket, and more data are expected. This might cause a problem if compressed bytes are read but do not generate an uncompressed byte, because the return value will be 0, which usually indicates EOF.

See madler/zlib Issue https://github.com/madler/zlib/issues/992

drbitboy commented 1 month ago

N.B. do not merge this PR yet; I still have some work to do to see if what I am trying to do is even feasible.

drbitboy commented 1 month ago

I added a few more bells and whistles.

But note that the primary changes in this PR are the ten new lines of code in gzread.c, and each of those changes has github comments associated with it. Also, those changes should not affect applications using zlib, because errno=EWOULDBLOCK/EAGAIN will not occur for blocking reads, and anyone using non-blocking reads would not be using zlib v1.3.1's gzread in the first place because it doesn't work in that environment.

Let me know if you have any questions.

drbitboy commented 1 month ago

P.S. My style is wrong in test/gznonblk.c; I can fix that.

Neustradamus commented 3 weeks ago

@madler: Have you seen this PR?