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

Audit bad uses of Read #4793

Closed
6 of 9 tasks
Stebalien opened this issue Mar 8, 2018 · 4 comments
Closed
6 of 9 tasks

Audit bad uses of Read #4793

Stebalien opened this issue Mar 8, 2018 · 4 comments
Labels
kind/bug A bug in existing code (including security flaws)

Comments

@Stebalien
Copy link
Member

Stebalien commented Mar 8, 2018

Read can:

  1. Fail to fully fill the target buffer even if there's more data to be read.
  2. Read data and return an EOF at the same time.

We haven't been handling these cases well leading to #4781. We need to audit all uses of Read.

Progress:

(I'm ignoring test cases for now)

@Stebalien Stebalien added the kind/bug A bug in existing code (including security flaws) label Mar 8, 2018
@kevina
Copy link
Contributor

kevina commented Mar 8, 2018

Not very common but, read can also:

  1. Read nothing, even when not at EOF, that is both data and err will be nil.

@Stebalien
Copy link
Member Author

Yes, but that case is also seriously discouraged. We should handle it but handling it may often involve returning a io.ErrNoProgress error (looping would likely be a bad idea in many cases).

@kevina
Copy link
Contributor

kevina commented Mar 8, 2018

Yes, but that case is also seriously discouraged. We should handle it but handling it may often involve returning a io.ErrNoProgress error (looping would likely be a bad idea in many cases).

Maybe, it is rare enough that it unlikely we need to write special code for it. This may mean looping until we get an EOF. The worst thing this will do is waste CPU time unless the Reader is broken in which case the function may never return. For example the fix #4710 (as of the time I wrote this comment) will simply loop until it gets an EOF.

Returning io.ErrNoProgress might be better, but it will also mean more code to handle a rare edge case.

The only thing we should not do is break out of a loop and not return any indication of an error when no data is read.

@Stebalien
Copy link
Member Author

The only thing we should not do is break out of a loop and not return any indication of an error when no data is read.

Yes. Absolutely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws)
Projects
None yet
Development

No branches or pull requests

2 participants