Skip to content

Mixed BitsPerSample per band silently uses bps[0] #1505

@brendancol

Description

@brendancol

Problem

TIFF allows a different bit depth per sample: BitsPerSample is a count-SamplesPerPixel array. The reader uses only bps[0] everywhere and assumes uniform bit width across bands.

Real-world example: a TIFF with SamplesPerPixel=4, BitsPerSample=(16, 16, 16, 8) (RGB at 16-bit, alpha at 8-bit). xrspatial decodes all four bands as 16-bit, producing garbage in the alpha band.

Where

xrspatial/geotiff/_dtypes.py and xrspatial/geotiff/_reader.py — bit-depth dispatch.

Fix sketch

Two reasonable options:

  1. Reject mixed bit depths with a clear error message.
  2. Decode each band at its own bit width into a separate array, then promote to a common dtype.

Option 1 is fine for now since this is rare in practice.

Severity

Low — uncommon in practice, but silent data corruption when it happens.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions