Research notes / Scientific archives
FITS archive checks: reordered pixels can preserve both checksums
/ Updated 23 October 2026 / Source synthesis and controlled software experiment
Two reordered pixels passed both FITS checksum checks without changing either stored checksum. A separate file lost its entire second image unit, yet every remaining unit still verified. An archive needs an expected file identity and inventory alongside its embedded checks.
On this page7 sections
Nine cases, with the actual pixels checked
FITS stores images and other scientific data in header/data units (HDUs). The checksum convention supplies a data-only check, DATASUM, and an entire-HDU check, CHECKSUM. NASA records its first use in 1994 and registration in 2007. It is an established archive mechanism, not a cryptographic authentication format. [1] [2]
The table reports checks before image-array access. Our starting image contains four signed 32-bit pixels: 10, 20, 30 and 40. Every single-unit fixture has one 2880-byte header and one padded 2880-byte data record. We alter disposable copies and then check raw bytes, decoded values and each HDU separately.
| Case | DATASUM | CHECKSUM | Pixels returned |
|---|---|---|---|
| Unchanged image | Valid | Valid | 10, 20, 30, 40 |
| One data bit flipped | Mismatch | Mismatch | 11, 20, 30, 40 |
| One padding bit flipped | Mismatch | Mismatch | 10, 20, 30, 40 |
| Two 32-bit pixels exchanged | Valid | Valid | 20, 10, 30, 40 |
| BSCALE changed to 2 | Valid | Mismatch | 20, 40, 60, 80 |
| Changed scale, sums regenerated | Valid | Valid | 20, 40, 60, 80 |
| Both checksum cards removed | Absent | Absent | 10, 20, 30, 40 |
| Only second HDU corrupted | Valid / Mismatch | Valid / Mismatch | 10, 20, 30, 40 / 11, 20, 30, 40 |
| Whole second HDU removed | Valid | Valid | 10, 20, 30, 40 |
The one-bit control changes 10 to 11 and fails both checks. The pixel swap changes the sequence to 20, 10, 30, 40 and passes both. Its whole-file SHA-256 differs from the separately retained original, while the embedded checksum cards are byte-for-byte unchanged. The padding-only control fails both checks while returning the original pixels. This contrast matters when diagnosing a mismatch. The pixel swap is an intentional checksum collision, not the valid-old-record case in our identity and freshness analysis.
The sum loses the order of its words
The convention adds big-endian 32-bit words using one's-complement arithmetic: overflow is folded back into the low end. Addition does not preserve word order. Exchanging complete, aligned words within the data records therefore preserves their sum. With an unchanged header, it preserves the whole-HDU check too. The proposal explicitly warns about word rearrangement in its introduction; this experiment reproduces that known boundary. [2, introduction and sections 2-3]
Our independent accumulator obtains a data sum of 100 before and after the swap. The whole-HDU sum remains 0xffffffff, the convention's negative zero. A regression test checks all 24 permutations of the four words. These selected transformations do not estimate how often storage systems reorder data or how frequently other corruption escapes detection.
Metadata can change the scientific values
Image interpretation follows physical value = BSCALE * stored value + BZERO. The scale and offset live in the header; a data-only checksum cannot cover them. [5]
Changing only BSCALE from 1 to 2 leaves the complete padded data record and its SHA-256 identical, while the decoded values become 20, 40, 60 and 80. DATASUM passes and CHECKSUM fails. After deliberately regenerating both checks, both pass for the changed interpretation. Regenerating checksums can accompany a legitimate processing step, but cannot establish that the step was scientifically correct.
For storage verification, we disable automatic scaling during checksum calls and decode the image through a separate read-only open. Astropy can change its in-memory header representation when image values are scaled. Keeping those operations separate makes clear which representation was checked. [5]
Reading the pixels changes which bytes get checked
Our ninth fixture flips one bit at file offset 2899, inside data-record padding and beyond the four pixels. The padded record's sum changes from 100 to 101. Both embedded checks fail on a fresh open, although the decoded pixels remain 10, 20, 30 and 40.
In a separate read-only open with scaling disabled, we call both verification methods, access hdu.data, then call them again. The return pair changes from (0, 0) to (1, 1). The complete file hash is identical before and after reading: no bytes were repaired or checksums regenerated.
The pinned image implementation explains the difference. Before loading, the checksum path reads the padded on-disk data span. Once the image array is loaded, it accumulates the array bytes, which exclude the altered padding. This is a version-scoped observation about the checked representation, not a claim that pixel data were silently changed. [4] [7]
For archive-byte verification, check a stable file before accessing image arrays and retain those verdicts. Reading all pixels and checking afterward does not establish the same coverage. Conversely, a checksum mismatch need not mean the decoded pixels differ: padding and headers are part of the protected record too. The other eight fixtures provide controls, with unchanged verification pairs across this unscaled data-access step.
Write-back can change values while every checksum passes
Added 23 October 2026. The checksum experiment above asks whether a file matches its stored sums. An archive migration also needs to ask whether the saved output preserves the intended input values. We tested Astropy 8.0.2 with NumPy 2.3.4 on 20 deliberately chosen integer images: ten numeric/null families in both a primary HDU and an IMAGE extension. None of the workflows assigns a pixel.
Eight workflows produce 160 configurations. A source-built CFITSIO 4.7.0 reader independently decodes both sides of each retained pair, giving 320 input/output observations per capture. In 30 successful outputs, exact values or missing-value locations differ from the input, although every inspected input and output HDU passes both checksums. These are selected counterexamples, not an archive failure rate.
| Workflow | Outputs inspected | Operation errors | Changed values or mask | Change hidden by double comparison |
|---|---|---|---|---|
| Read-only array access | 20 | 0 | 0 | 0 |
| Update without array access | 20 | 0 | 0 | 0 |
| Update, header edit only | 20 | 0 | 0 | 0 |
| Update after array access | 20 | 0 | 12 | 0 |
| Update with scale_back | 20 | 4 | 6 | 4 |
| Update with unscaled array access | 20 | 0 | 0 | 0 |
| Rewrite after array access | 20 | 0 | 12 | 0 |
| Rewrite with unscaled array access | 20 | 0 | 0 | 0 |
The four scale_back operations that raise OverflowError retain readable bytes but remain failed operations. They are not among the thirty changed successful outputs. Read-only access, no-array updates and the raw-data controls preserve values and masks in these fixtures; this does not certify those options for arbitrary FITS data.
The payload, its interpretation and the values are distinct
In a signed 64-bit fixture with an unused BLANK marker, update-mode array access is followed by output that still declares integer BITPIX=64 but contains floating-point representations. A fresh reader therefore returns very different integers. With scale_back=True, integer storage returns, but an intermediate rounding loss remains. For a separate unsigned 16-bit fixture, the pixel-payload hash stays unchanged while BZERO and BLANK disappear, changing both physical values and nullness. The writer method and three exact examples retain the headers, payloads and source explanation.
Astropy's version-pinned documentation warns that accessing scaled data in update mode can change what is later saved. The tested implementation also converts some BLANK-bearing images with unit input scaling. Regenerated checksums describe the resulting bytes, not their equivalence to the source measurement. [7] [8]
Two readers can agree after losing the same distinction
The signed fixture contains the exact integer 9007199254740993. Its scale_back output contains 9007199254740992. CFITSIO's integer read preserves that difference. When both sides are requested as double precision, however, they compare equal. This conceals changes in 4 configurations, spanning two fixture families and both HDU roles.
The CFITSIO raw-value path, separate null flags and exact rational reconstruction agree with the original byte oracle throughout. The failure here is the acceptance comparison's lossy representation, not evidence that CFITSIO misreads the declared integers. Its image API lets the caller choose the output type. [9]
Acceptance rule: keep the source immutable, write a new destination, then compare HDU identities, intended interpretation metadata, exact valid values and separate null masks. Verify checksums independently. Our JSON exports use strings for exact numbers and null for missing pixels, so the evidence itself does not repeat a binary64 comparison loss.
The study covers uncompressed, one-dimensional images of at most four pixels with unit input scaling. It does not test tables, compressed HDUs, non-unit input scales, concurrency or durability. The upstream BLANK fix [10] predates this synthesis and was merged, but was not executed here. These observations concern the pinned writer, not every release or a claim of first discovery.
Download the complete reproducible evidence package, generated table and exact examples, file hashes and evidence map and reproduction instructions. The independent-reader method distinguishes repeated reads of retained outputs from rerunning the writer.
A returned file handle is not the verdict
All nine files opened and passed structural verify("exception"). The bit-flipped image also opened without a warning under default options. With checksum=True, the library returned the file and issued checksum warnings. With both cards absent, it returned without a checksum warning. Those are measured outcomes under the normal warning policy, not exceptions being caught and ignored.
Astropy documents optional verification and warning-based mismatch reporting. Its explicit methods distinguish three states. Compare them by value, not truthiness: in Python, bool(2) is true. [3] [4]
| API result | Valid | Failed | Absent |
|---|---|---|---|
| Astropy verify methods | 1 | 0 | 2 |
| CFITSIO DATAOK / HDUOK | 1 | -1 | 0 |
The CFITSIO codes are documented and exercised in our separate 4.7.0 native controls: unchanged, pixel-bit damage, padding-bit damage and absent keywords. They are not a replay of all nine original cases. The padding mismatch remains a mismatch after pixel access in those controls. DATAOK and HDUOK are output verdicts, separate from operational status; a nonzero test would accept the mismatch value. [6]
Check the expected inventory as well as each unit
The two-HDU corruption fixture verifies its primary HDU and fails its second HDU. Checking only the first would miss the injected fault. The removal fixture instead drops the entire second HDU: the remaining file is structurally readable and its surviving checks pass. Comparing the observed one-HDU inventory with the expected two-HDU inventory detects the omission; the per-HDU sums cannot supply that expectation.
For an archive ingest or restore, keep an independently protected manifest of expected files, digests and HDU identities. Explicitly distinguish absent, failed and valid checks for every expected unit. Preserve scaling and other interpretation metadata, and validate application-level expectations such as dimensions and expected extensions. A count alone is not an identity check.
Verify a stable, read-only copy before any checksum regeneration or transformation. A digest whose reference can be replaced alongside the file does not authenticate an archive. This complements the different read-coverage problems demonstrated for Parquet and the external interpretation dependencies demonstrated for HDF5 virtual datasets.
Run the experiment
Download the Python harness, pinned dependencies and complete JSON observations. The harness creates its own temporary files, accepts no input-data path and refuses to overwrite an existing output. It records raw hashes, per-HDU sums, return codes, warnings and decoded arrays.
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
.venv/bin/python observe.py --output my-results.jsonRecorded with Python 3.12.3, Astropy 8.0.2 and NumPy 2.3.4 on 2026-10-18. Fixtures and hashes reproduce exactly under the recorded dependencies; generation time and platform metadata describe each run separately.
These are constructed, uncompressed image cases, not telescope measurements or a sampled incident population. The experiment does not test compressed images, tables, concurrent modification, remote storage, physical-media faults or power-loss behavior. Its contribution is a reproducible connection between the checksum algebra, application API and archive acceptance policy, not a new failure-rate estimate.
Primary sources
- NASA FITS registry: Checksum Keyword Convention
- Seaman, Pence and Rots: FITS Checksum Proposal (23 May 2002), introduction and sections 2-3
- Astropy: verification using the FITS checksum keyword convention
- Astropy v8.0.2: verify_datasum, verify_checksum and warning handling
- Astropy: FITS image scaling with BSCALE and BZERO
- CFITSIO C user's guide: File Checksum Routines and DATAOK/HDUOK
- Astropy v8.0.2 image.py: loaded-image checksum path
- Astropy v8.0.2 image documentation: update-mode scaling, raw access and scale_back
- CFITSIO C user's guide: image output types and separate null arrays
- Astropy upstream PR 20517: BLANK and ignore_blank fix, merged but not executed in this study