Skip to content

UTF-16 decoder can panic on invalid input #44

@vickenty

Description

@vickenty

This program panics (playground):

use encoding_rs::CoderResult;

fn main() {
    let d = &mut encoding_rs::UTF_16BE.new_decoder_without_bom_handling();
    let b = &mut [0; 4];

    assert_eq!(
        d.decode_to_utf8(&[217, 99], b, false),
        (CoderResult::InputEmpty, 2, 0, false)
    );
    
    let _ = d.decode_to_utf8(&[217, 99], b, true);
}
thread 'main' panicked at 'index out of bounds: the len is 4 but the index is 4', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/encoding_rs-0.8.20/src/lib.rs:3884:21

This is a minimized example of a bug found by a fuzzer in another crate. Let me know if you want full details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions