You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reader should be vetted to ensure it handles 0-length reads in a sane fashion. This is inspired by comments on #13049.
A few things need to be ensured:
The documentation on Reader discourages returning 0 from read(). It should certainly be allowed, but implementors should be encouraged to avoid returning 0 if possible.
The default methods on Reader should all behave sanely if a single call to read() returns 0.
Less importantly, the default methods should handle a Reader that returns 0 forever. Practically speaking, this means that if the method employs a loop, it should also employ a counter to count how many 0-length read()s there have been in a row, and if it passes some threshold (TBD, but maybe something like 1000) then it should return an error. There should also be a new IoErrorKind defined for this case (Go uses one called ErrNoProgress, that seems a sensible name).
Any clients of Reader in std and the associated libraries should also be checked to make sure they handle 0-length reads.
The simplest way to implement this may be to add another default method read_at_least() that takes a count of how many bytes it should ensure it has read. This method can then deal with counting 0-length reads and setting the proper error, and then everything that reads in a loop can use r.read_at_least(but, 1) so they don't have to deal with it.
The text was updated successfully, but these errors were encountered:
Reader should be vetted to ensure it handles 0-length reads in a sane fashion. This is inspired by comments on #13049.
A few things need to be ensured:
read()
. It should certainly be allowed, but implementors should be encouraged to avoid returning 0 if possible.Reader
should all behave sanely if a single call toread()
returns 0.Reader
that returns 0 forever. Practically speaking, this means that if the method employs a loop, it should also employ a counter to count how many 0-lengthread()
s there have been in a row, and if it passes some threshold (TBD, but maybe something like 1000) then it should return an error. There should also be a newIoErrorKind
defined for this case (Go uses one calledErrNoProgress
, that seems a sensible name).std
and the associated libraries should also be checked to make sure they handle 0-length reads.The simplest way to implement this may be to add another default method
read_at_least()
that takes a count of how many bytes it should ensure it has read. This method can then deal with counting 0-length reads and setting the proper error, and then everything that reads in a loop can user.read_at_least(but, 1)
so they don't have to deal with it.The text was updated successfully, but these errors were encountered: