-
Notifications
You must be signed in to change notification settings - Fork 117
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
EncoderWriter::write_all leads to WriteZero error #148
Comments
At first glance this appears to be the issue I reported in rust a while back: rust-lang/rust#56889. tl;dr Write::write_all erroneously (IMO) interprets an
|
Feel free to re-open if something new comes to light, or if that rust bug is ever fixed 😢 |
I ended up spending quite a bit of time trying to figure out what's going on when I started randomly getting hit by this. It would be useful to add that |
It's documented at https://github.com/marshallpierce/rust-base64/blob/master/src/write/encoder.rs#L243, but I'm open to PRs to explain it differently, and I agree that it would be nice to offer a suggested mitigation. |
Unfortunately docs.rs doesn't make the documentation on implemented traits particularly obvious, so will see about adding this to the main documentation of the struct as this is something that would be pretty important for users to know about. In my case I worked around it by adding a wrapper with |
Hi @marshallpierce, I'm facing the same problem and came across this issue. As rust-lang/rust#107200 mentioned, IMHO, as an adapter, For example, change the code below: if self.output_occupied_len > 0 {
let current_len = self.output_occupied_len;
return self
.write_to_delegate(current_len)
// did not read any input
.map(|_| 0);
} to this: while !self.has_spare_capacity_to_encode_more() {
let current_len = self.output_occupied_len;
let res = self.write_to_delegate(current_len)?;
if res == 0 {
return Ok(0);
}
} We even don't need to flush all the contents in output buffer, since we don't want it to behave like |
I wonder if such a change would require an MSRV update? Or maybe most users don't care. Technically the https://github.com/rust-lang/rust/pull/107200/files / https://github.com/rust-lang/rust/pull/114897/files combo only applies to 1.73+. |
I don't know. But maybe some crates will rely on the behaviors described in the doc to work correctly. |
Using
base64::write::EncoderWriter
with a writer that accepts very limited writes leads toEncoderWriter::write_all
calls failing.To reproduce (playground link)
To reproduce 2 (expanded the default Write::write_all implementation) (playground link)
Click to expand!
Expected behavior
Encoding succeeds, and the contents of
vec
are the same I would get if I were to callbase64::encode(contents)
.Observed behavior
writer.write_all(&contents)
fails withCustom { kind: WriteZero, error: "failed to write whole buffer" }
Environment
rust:
stable
base64:
0.13.0
The text was updated successfully, but these errors were encountered: