Skip to content

The number reader methods in should raise a condition if not enough bytes could be read #8834

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

Closed
rapha opened this issue Aug 29, 2013 · 2 comments

Comments

@rapha
Copy link
Contributor

rapha commented Aug 29, 2013

Currently the various number reader methods defined in

std::rt::io::extensions::ReaderByteConversions

are based on read_u8_ and read_i8_ which simply return 0 if the byte could not be read. This means that the user can silently read bad values, e.g.

$ rusti
rusti> use std::rt::io::Reader; 
rusti> use std::rt::io::extensions::ReaderUtil;
rusti> use std::rt::io::extensions::ReaderByteConversions;
rusti> use std::rt::io::mem::MemReader; 
rusti> MemReader::new(~[1]).read_be_u32_()
16777216 

I suggest that a read_u8_ and read_i8_ should raise an EndOfFile, similarly to ReaderUtil::push_bytes, so the user can handle that case.

@alexcrichton
Copy link
Member

I think that the actual bug here is that MemReader doesn't raise on io_error once None is returned.

@alexcrichton
Copy link
Member

Closed by #11946

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

2 participants