Skip to content

DecoderReader accepts incorrect input #226

@mina86

Description

@mina86

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:?}");
}

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions