You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Sad Catapella N1][Correctness] Big-endian int8/int16 histogram blocks are reinterpreted as native-endian pixel values #25
Normalization adversarial audit, Batch 1, mainf784c95e3049483f87466150ffc5764375fa631d. Confirmed source-level defect with isolated NumPy byte-order probe; full package tests not executed.
Evidence
_measure, lines 399–411 normalizes the declared dtype to native order via check_supported, but passes original blocks unconverted.
_small_integer_histogram, lines 443–456 uses values.view(f'u{dtype.itemsize}'), which reads bytes as native-endian unsigned values, without converting from a block's actual byte order. Both whole-plane and blockwise APIs use this fast path for 8-/16-bit integers.
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