NiVO / BY TECHNOGISGermany · Indonesia
Preview integrity tutorial

PNG Chunk CRC: Check a Drone Preview Exchange Without Repairing the File

Inspect one bounded PNG chunk, compare its stored CRC with the type-and-data checksum, and keep integrity evidence separate from image acceptance.

PNG Chunk CRC: Check a Drone Preview Exchange Without Repairing the File

Investigate the received preview before exporting it again

A PNG preview can be useful during a drone mapping handoff, but a readable thumbnail is not a complete integrity report. If two teams receive different behavior from an exchanged image, preserve the received bytes before opening and saving another version. A checksum comparison can help describe a particular chunk without silently changing the evidence. The first task is to identify which version was received and what was actually checked. Re-exporting the file at the beginning of an investigation can conceal the difference that the receiving team needs to explain.

This tutorial inspects an isolated PNG chunk supplied as bytes in memory. The teaching input is the standard empty IEND chunk, not a complete image, a captured aerial photograph, or a NiVO export. That deliberately small scope makes the checksum boundary visible. The procedure does not locate chunks inside an arbitrary file or decide whether a preview represents an accepted orthomosaic. Use it to understand a finding reported by an agreed image inspection workflow, then keep the image, spatial references, and project acceptance evidence under their own review criteria.

Separate chunk length from the checksum input

The W3C PNG specification describes a chunk as a length field, a four-byte type, a data field, and a four-byte CRC. The length counts the data bytes alone. The CRC covers the type and data, excluding the length field, and is present even when the data field is empty. The stored CRC is ordered most significant byte first. These distinctions matter when reproducing a mismatch: hashing every byte in the chunk would answer a different question from comparing the checksum defined by PNG.

Treat the declared length as a framing instruction that must be checked before selecting the checksum input. A truncated buffer, an unexpected extra byte, or an unreasonable declared size should stop this bounded exercise before a comparison is reported. The one-megabyte limit below is a local teaching guard, not the format maximum or a recommended delivery limit. For an actual large file, use an appropriate maintained parser and a resource policy suited to the task. Do not allocate arbitrary amounts of memory merely because a received length field requests them.

NiVO VTOL V7 with a white fuselage, lift rotors, and yellow wing tips
NiVO VTOL V7 with a white fuselage, lift rotors, and yellow wing tips.Source: NiVO / TechnoGIS catalogue materials supplied by the site owner · Catalogue photo
Product context only; this photograph does not depict the constructed examples in this article.

Compare an exact isolated chunk in Python

The function checks an immutable bytes object representing exactly one chunk. It reads the data length in big-endian order, applies the declared size guard, and requires the entire buffer length to match the chunk layout. It also limits the four type bytes to letters for this exercise. The computed value comes from zlib.crc32 over the type and data slice; the stored value comes from the final four bytes. Returning both hexadecimal values alongside the equality result makes the finding easier to reproduce than a bare pass label.

Run the example with Python in a local working environment. The fixed twelve-byte IEND input has zero data bytes and a stored CRC of AE426082. Both reported checksum values should therefore be ae426082 and the comparison should be True. The example neither downloads nor writes any file. A separate test that changes a type byte without updating the stored CRC should report a mismatch, while removing a byte should fail the framing check. Those are different findings and should remain distinguishable in an investigation record.

import zlib

def inspect_chunk(chunk, max_data=1048576):
    if not isinstance(chunk, bytes) or len(chunk) < 12:
        raise ValueError("Expected at least twelve isolated chunk bytes")
    if type(max_data) is not int or max_data < 0:
        raise ValueError("Invalid local data-size limit")
    length = int.from_bytes(chunk[:4], "big")
    if length > max_data or len(chunk) != length + 12:
        raise ValueError("Chunk length or local size limit failed")
    kind = chunk[4:8]
    if not all(65 <= b <= 90 or 97 <= b <= 122 for b in kind):
        raise ValueError("Chunk type must contain four ASCII letters")
    stored = int.from_bytes(chunk[-4:], "big")
    computed = zlib.crc32(chunk[4:-4])
    return kind.decode("ascii"), f"{stored:08x}", f"{computed:08x}", stored == computed

# One isolated IEND chunk, not a complete PNG image.
toy = bytes.fromhex("0000000049454e44ae426082")
print(inspect_chunk(toy))

Interpret a mismatch without inventing a repair

A mismatch establishes that the stored checksum and the recalculated value disagree for the supplied type-and-data bytes. It does not identify when the difference occurred or which copy contains the intended content. Record the received version, the chunk location supplied by the actual parser, the type, the declared length, and the two values. If another copy is available, compare its identity and provenance before treating it as a replacement. Avoid attributing the issue to a camera, network transfer, or editing application without evidence from that particular exchange.

Recalculating the stored CRC would make the current bytes internally consistent with a new checksum, but would not demonstrate that those bytes are the intended original. That is why this function reports rather than repairs. Request a checked replacement from the producer or follow the project recovery procedure while retaining the problematic version. A matching value has limits as well: Python documents that CRC32 is not cryptographically strong. Do not use this comparison as proof of authorship, an authenticity signature, or a substitute for the project procedure that identifies the received deliverable.

Keep chunk integrity separate from full PNG validation

The function does not inspect a PNG signature, enforce chunk order, require an image header, decompress image data, or confirm that an end marker is in the correct position. It checks only the isolated bytes supplied by the caller. Consequently, the successful IEND example is not a valid standalone PNG and must never be published or described as one. An actual receiving workflow needs complete format validation and image decoding where those are required. Keep those results separate so that one checksum match cannot be mistaken for a complete readability test.

Geospatial interpretation is another independent boundary. A PNG may be a presentation preview rather than a referenced raster. An internally consistent chunk cannot establish a coordinate reference, ground resolution, extent, capture date, or positional accuracy. Preserve any accompanying spatial metadata and identify the intended use of the image. If a project requires a georeferenced analytical raster, assess that delivered product through the agreed GIS workflow. Do not turn a preview checksum finding into an unsupported claim that the underlying drone survey or its derived map has been validated.

Deliver a finding that preserves the investigation trail

A useful handoff note names the unchanged received file, the inspection tool and version, the chunk under examination, and the exact check performed. State whether the result was a framing rejection or a stored-versus-computed CRC disagreement. Include any separately obtained full-decoder result without implying that it came from this small function. The teaching example can help another reviewer understand the calculation boundary, but the project report must identify the actual parser and actual input that produced its finding. Keep synthetic demonstration output clearly separated from evidence about received imagery.

When a replacement arrives, retain its relationship to the original issue and repeat the relevant checks on that version. Record the producer response and the receiving-side outcome instead of overwriting the investigation history with the latest successful export. For a NiVO-related data discussion, this approach keeps a technical preview problem specific and reproducible. The team can explain what is known about the exchanged bytes while continuing the separate image, spatial-reference, and project-content reviews needed for the intended deliverable.

Technical references

  1. W3C PNG: chunk layout and CRC algorithm ↗
  2. Python zlib: crc32 and its authentication limits ↗
← All articles

Related articles

All articles ↗
LET’S TAKE FLIGHT

Your next mission
starts with a conversation.

Talk to our team