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

ReadBytesExt: document the danger of reading after an error #209

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Aug 2, 2024

  1. ReadBytesExt: document the danger of reading after an error

    std::io::Read::read_exact documentation says that if an error occurs,
    the state of the reader is unspecified: it may have consumed some
    number of bytes (between zero and the size of the buffer).
    
    This makes it unwise to continue reading after an error, since it's not
    possible to know where the read begins.
    
    A caller may be surprised by this issue, for example by calling
    read_u16() until it fails, then calling read_u8() to collect a remainder
    byte. This is not guaranteed to work.
    
    This was specifically observed to behave one way on rust 1.79.0, and
    then a different way in rust 1.80.0 when using std::io::Cursor as the
    reader.
    
    Closes BurntSushi#208 (Documents the problem, which is the best we can do.)
    eric-seppanen committed Aug 2, 2024
    Configuration menu
    Copy the full SHA
    a93ba2c View commit details
    Browse the repository at this point in the history