# FITS migration checks: a second reader can still hide integer loss

23 October 2026. Controlled software experiment; continuation of research
PR #1789 and the existing FITS archive analysis, not a new topic page.

## Main result

CFITSIO 4.7.0 independently decoded the bytes retained from the Astropy 8.0.2
write-back experiment. It agreed with the original exact-value oracle on all
320 input/output observations. All embedded checksums passed, yet 30 of the
160 output configurations had different exact values or missing-value locations
from their inputs. All 30 came from operations recorded as successful.

A second library is useful, but **the comparison representation matters too**.
For four of those configurations, reading both input and output as double
precision produced equal arrays. Comparing those arrays would have accepted a
changed integer. This is a concrete false-equivalence control, not evidence
that CFITSIO misread the declared on-disk integer representation.

## Experimental design

The inputs are the original twenty synthetic images: ten numeric/null families,
each in a primary HDU and an IMAGE extension. The parent study exercised eight
write/read workflows, making 160 configurations. We replayed both sides of
each saved pair, using the retained bytes and SHA-256 identities. We did not
regenerate, repair or rewrite the evidence.

The new C probe opens ordinary temporary files READONLY. It verifies every HDU
before data access, reads through three API paths, and checks every HDU again.
The paths are a suitably typed physical read (signed/unsigned 64-bit integers
where appropriate), a deliberate double-precision read, and an unscaled
native read with a separate null mask. Exact rational arithmetic combines the
last path with independently read scaling metadata. The Python orchestrator
uses only the standard library: it never imports Astropy or NumPy.

Two complete captures agree exactly on all 320 observations and four
negative/positive controls. Each capture contains 160 input and 160 output
observations, not 320 unique images. The same twenty inputs recur across the
eight workflows. These are chosen boundary fixtures, not a representative
sample; counts are not failure rates and do not merit population confidence
intervals.

## Results

| Parent workflow | Compared outputs | Changed exact values or mask |
| --- | ---: | ---: |
| Read-only array access | 20 | 0 |
| Update without array access | 20 | 0 |
| Update, header edit only | 20 | 0 |
| Update after array access | 20 | 12 |
| Update with scale_back | 20 | 6 |
| Update with unscaled array access | 20 | 0 |
| Rewrite after array access | 20 | 12 |
| Rewrite with unscaled array access | 20 | 0 |

Every checksum passed independently under CFITSIO, both before and after
pixel reads. The parent records four scale_back OverflowErrors. Their retained
bytes remain explicitly failed-write evidence; they are not successes and
are not among the 30 changed outputs.

### Equal doubles can conceal unequal integers

The signed64_unused_blank input contains 9007199254740992,
9007199254740993 and 9007199254740994. Its scale_back output contains
9007199254740992, 9007199254740992 and 9007199254740994.

CFITSIO's integer path preserves this distinction. Its requested double path
maps the middle input integer to 9007199254740992, so the two double arrays
compare equal. The same concealment occurs with the signed64_present_blank
case. Each occurs in both HDU roles, giving four configurations.

This is an acceptance-test failure caused by lossy normalization. A second
reader and valid checksums cannot compensate for throwing away the very
distinction the comparison is supposed to check. Retain integer precision and
a separate null mask through the comparison and through machine-readable
exports; our JSON stores numeric values as strings.

### The independent controls really reject damage

We also replay an unchanged signed-16 input, one flipped pixel bit, one
flipped padding bit beyond the pixel array, and a copy without checksum cards.
CFITSIO returns valid, mismatch, mismatch and absent respectively. Those
verdicts remain unchanged after reading the pixels. The padding case preserves
the interpreted pixels; the pixel-bit case changes them.

This additionally contrasts with the existing version-pinned Astropy
read-state result, where loading the array changed coverage of padding.
It does not establish that every CFITSIO path, compressed HDU or future
release has the same behavior.

## Why these checks answer different questions

The [CFITSIO image API](https://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c_user/node40.html)
permits caller-selected output types and returns null flags separately.
We use the null-array variant, avoiding ambiguity between a valid zero
and a missing pixel. Output type selection is part of the experiment.

The [scaling override](https://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c_user/node76.html)
changes the library's conversion parameters without changing header cards.
Combined with the documented
[scaling equation](https://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c_user/node26.html),
it allows an exact comparison for these unit-scale integer fixtures.

The [checksum API](https://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c_user/node50.html)
has two verdict outputs separate from operational status. Valid is 1,
absent is 0, mismatch is -1. Testing truthiness would accept a mismatch.
Our controls exercise these states instead of treating successful function
execution as a verification verdict.

The result therefore distinguishes four obligations: readable structure,
byte-level checksum agreement, correct value interpretation, and preservation
of the intended source values. The first three can hold while the fourth fails.

## Version and evidence boundaries

The tested writer was Astropy 8.0.2 with NumPy 2.3.4; the newly executed reader
was source-built CFITSIO 4.7.0 on Linux x86-64. This is independent-library
verification of retained synthetic outputs, not a second implementation of
the original writer workflow, an independent research team, or a replication
on another architecture.

The [upstream BLANK fix](https://github.com/astropy/astropy/pull/20517) was
merged before this run. The retained PyPI API receipt advertised 8.0.2 and
listed no later 8.x release at collection time. We do not invent a newer
released version or claim to have executed the merge. A future migration
must repeat both read and write acceptance tests on its exact selected build.
No first-discovery claim, hardware conclusion or archive incident rate follows.

Only uncompressed, one-dimensional images with at most four pixels and unit
input BSCALE are represented. Tables, compressed images, non-unit scales,
concurrent mutation, durability and power loss were not tested.

## Reproduction

Download the [official 4.7.0 source](https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio-4.7.0.tar.gz).
Its SHA-256 must be
ce573bbea8e75b429f8c3d3e86498741ba3dc9628a1530d2f65268397ad059e8.
The NASA license permits use subject to its notice/disclaimer; it is retained
in the upstream archive. No library binary or copied source is vendored here.
In a disposable extracted source directory:

```sh
./configure --disable-shared --enable-static --disable-curl --without-fortran
make -j2 libcfitsio.la
```

From this research directory, set CFITSIO_SRC to that build directory:

```sh
gcc -std=c11 -O2 -Wall -Wextra -Werror -I"$CFITSIO_SRC" reader.c \
  "$CFITSIO_SRC/.libs/libcfitsio.a" -lz -lm -o /tmp/hesela-fits-reader
python3 replay.py --reader /tmp/hesela-fits-reader --output reproduced.json
CFITSIO_READER=/tmp/hesela-fits-reader python3 -m unittest -v test_replay
CFITSIO_READER=/tmp/hesela-fits-reader python3 -O -m unittest -v test_replay
```

The probe is bounded for these fixtures, not an untrusted-file validator.
Captures refuse overwrite. Temporary files are read-only to CFITSIO and are
byte-compared after each call; only the harness's own temporary directory is
removed. Native statuses, both checksum states, null arrays and exact
values are retained. Sources and compilation identities accompany the results.

## Integration

Extend the existing
[FITS archive analysis](https://hesela.com/analyses/fits-checksums-pixel-order-and-coverage/)
with one write-back/acceptance section and publish this evidence beside the
parent dataset. Enrich the existing fits and fits-checksum records only,
preserving IDs, definitions and original publication dates.
The public article's CFITSIO row currently describes documentation only;
change that wording only when this tested evidence is actually linked there.

The proposed synthesis is: an archive migration must verify the saved output
against an independently preserved source contract using an exact-enough
representation, including nullness and interpretation metadata. A checksum
validates current bytes against its stored sum, not preservation of the
source measurement; cross-reader agreement after a lossy cast can hide a
real change.

Status: tested research on the existing PR. No public page edit, merge,
deployment or browser QA is represented by this packet.
