Skip to content

[Sad Catapella N1][Correctness] Big-endian int8/int16 histogram blocks are reinterpreted as native-endian pixel values #25

Closed

Description

@guijacquemet

Scope / classification

Normalization adversarial audit, Batch 1, main f784c95e3049483f87466150ffc5764375fa631d. Confirmed source-level defect with isolated NumPy byte-order probe; full package tests not executed.

Evidence

Minimal counterexample

np.array([1,2,3],dtype='>u2') has numeric values 1,2,3, but arr.view('u2') on a little-endian host produces [256,512,768]. The current fast path builds the histogram over those wrong values and calls it the numeric original. An isolated NumPy probe confirmed the reinterpretation; this is not a repository test run.

Impact

Wrong minimum/maximum, wrong bin counts and consequently wrong normalization statistics for big-endian 16-bit images, an important microscopy storage format. No explicit warning or refusal.

Fix / acceptance

Normalize values to the declared native dtype by value, not by raw bytes, before reinterpretation (or use a byte-order-aware bit mapping). Preserve signed integer order, streaming and existing speed. Test >i2, >u2, <i2, <u2 on native and non-native hosts, 8-bit controls, strided blocks and real TIFF big-endian fixture; assert numerical minima/limits/counts against an independent reference, whole-block parity and no extra unbounded copies. Benchmark conversion overhead and an optional Numba primitive only after correctness is fixed. No source modified.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions