TechnikTobi / little_exif

A little library for reading and writing EXIF data in pure Rust.
Apache License 2.0
22 stars 5 forks source link

JPEG optimization and panics #8

Closed Xuf3r closed 7 months ago

Xuf3r commented 7 months ago

Resolves #6 I have no idea what exactly is wrong with that image. I traced it and it tries to shove 22 bytes into from_u8_vec_macro which obviously fails since u32 != 22/4.

if let Ok(tag) = ExifTag::from_u16(hex_tag)
            {
                // ...for a SubIFD...
                if let Some(subifd_group) = tag.is_offset_tag()
                {
                    // ...perform a recursive call
                    let offset = from_u8_vec_macro!(u32, &raw_data, endian) - given_offset;

In this loop the STRING tag, which seems to indeed be valid data for some reason is interpreted as an offset tag instead thus invoking the macro where the assertion fails. Perhaps this is some unhandled case of metadata structure from a camera manufacturer.

Windows explorer also can't edit the Strings in that image so i consider that a mangled metadata case. We panic instead of assert so that it can be caught in runtime when used a dependency. I consider this a reasonable workaround for now.

Partially fixes #7 Impoves performance of parsing the JPEG file to seek and remove APP1 segment.