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

DecoderReader accepts incorrect input #226

Closed
mina86 opened this issue Feb 10, 2023 · 2 comments · Fixed by #238
Closed

DecoderReader accepts incorrect input #226

mina86 opened this issue Feb 10, 2023 · 2 comments · Fixed by #238
Assignees

Comments

@mina86
Copy link
Contributor

mina86 commented Feb 10, 2023

When parts read from underlying reader include valid padding the
reader accepts the input even if there’s more data to follow. In this
example the reader produces string AA==AA==AA== which should result
in an error but instead generates three zero bytes.

struct Foo(usize);

impl std::io::Read for Foo {
    fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
        if self.0 == 0 {
            return Ok(0);
        }
        self.0 -= 1;
        buf[..4].copy_from_slice(b"AA==");
        Ok(4)
    }
}

fn main() {
    use std::io::Read;
    use base64::engine::general_purpose::STANDARD;

    let mut decoder = base64::read::DecoderReader::new(Foo(3), &STANDARD);
    let mut vec = Vec::new();
    let res = decoder.read_to_end(&mut vec);
    print!("{res:?} {vec:?}");
}
@marshallpierce
Copy link
Owner

Good find, thanks for the heads up.

@marshallpierce marshallpierce self-assigned this Feb 21, 2023
marshallpierce added a commit that referenced this issue May 21, 2023
Fixes #226.

DecoderReader now keeps more state so that erroneous internal padding that happens to fall right on a read buffer boundary isn't silently ignored.
marshallpierce added a commit that referenced this issue May 21, 2023
Fixes #226.

DecoderReader now keeps more state so that erroneous internal padding that happens to fall right on a read buffer boundary isn't silently ignored.
marshallpierce added a commit that referenced this issue May 21, 2023
Fixes #226.

DecoderReader now keeps more state so that erroneous internal padding that happens to fall right on a read buffer boundary isn't silently ignored.
marshallpierce added a commit that referenced this issue May 21, 2023
Fixes #226.

DecoderReader now keeps more state so that erroneous internal padding that happens to fall right on a read buffer boundary isn't silently ignored.
marshallpierce added a commit that referenced this issue May 21, 2023
Fixes #226.

DecoderReader now keeps more state so that erroneous internal padding that happens to fall right on a read buffer boundary isn't silently ignored.
@marshallpierce
Copy link
Owner

This will be fixed in 0.21.1 momentarily.

crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this issue Jun 12, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [base64](https://github.com/marshallpierce/rust-base64) | dependencies | patch | `0.21.0` -> `0.21.2` |

---

### Release Notes

<details>
<summary>marshallpierce/rust-base64</summary>

### [`v0.21.2`](https://github.com/marshallpierce/rust-base64/blob/HEAD/RELEASE-NOTES.md#&#8203;0212)

[Compare Source](marshallpierce/rust-base64@v0.21.1...v0.21.2)

-   Rollback MSRV to 1.57.0 -- only dev dependencies need 1.60, not the main code

### [`v0.21.1`](https://github.com/marshallpierce/rust-base64/blob/HEAD/RELEASE-NOTES.md#&#8203;0211)

[Compare Source](marshallpierce/rust-base64@v0.21.0...v0.21.1)

-   Remove the possibility of panicking during decoded length calculations
-   `DecoderReader` no longer sometimes erroneously ignores padding  [#&#8203;226](marshallpierce/rust-base64#226)

#### Breaking changes

-   `Engine.internal_decode` return type changed
-   Update MSRV to 1.60.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS45OC4wIiwidXBkYXRlZEluVmVyIjoiMzUuMTAwLjEiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1907
Reviewed-by: crapStone <crapstone@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
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

Successfully merging a pull request may close this issue.

2 participants