Enet4 / dicom-rs

Rust implementation of the DICOM standard
https://dicom-rs.github.io
Apache License 2.0
416 stars 81 forks source link

detect_preamble and in extension from_reader_with_all_options doesn't check for size #404

Closed DerOrfa closed 1 year ago

DerOrfa commented 1 year ago

In detect_preamble in mem.rs

        if &buf[0..4] == b"DICM" {
            return Ok(ReadPreamble::Never);
        }

is done without checking if buf actually has at least 4 bytes, leading to panic when, for example, trying to read empty files with from_reader_with_all_options and friends.

Should return with io::Error.

Enet4 commented 1 year ago

Thank you for reporting! Would you be able to send in a pull request?