image-tiff icon indicating copy to clipboard operation
image-tiff copied to clipboard

Tags of type Short are read as Unsigned

Open lgpasquale opened this issue 2 years ago • 3 comments

When reading a tag that fits into the offset field and is of type SHORT (Tiff type 3) the value is returned as Value::Unsigned instead of Value::Short.

I believe the issue lies in line 407 of ifd.rs.

The right behavior is what can be seen when multiple values are handled (line 475 of ifd.rs)

lgpasquale avatar May 19 '23 15:05 lgpasquale

This makes sense to fix, though the annoying part is figuring out whether anywhere else in the code is relying on the current behavior. Or whether it is likely to break any downstream users and thus might warrant additional caution

fintelia avatar May 29 '23 06:05 fintelia

It looks like a minimal fix is something like so.

This will make all the tests run successfully.

Regarding side effects I would suppose anyone interfering with the TAG data directly might have colliding types. What use case brought you to this, @lgpasquale ?

I suppose taking care of SSHORT is needed as well? This would require introducing an additional Value:

pub enum Value {
    Byte(u8),
    Short(u16),
    Signed(i32),
    SignedBig(i64),
    Unsigned(u32),
    UnsignedBig(u64),
    Float(f32),
    Double(f64),
    List(Vec<Value>),
    Rational(u32, u32),
    RationalBig(u64, u64),
    SRational(i32, i32),
    SRationalBig(i64, i64),
    Ascii(String),
    Ifd(u32),
    IfdBig(u64),
}

Jondeen avatar Sep 06 '23 09:09 Jondeen

Adding support for SSHORT (i16) and SBYTE (i8) at #234, I can try to add the patches for the casting of SHORT as u16 instead of u32 in a follow up PR if there's interest?

weiji14 avatar May 17 '24 14:05 weiji14