Topics
Recent articles

DevOps & Cloud

Detect a Truncated Hero Image After HTTP 200

Learn how to verify deployed hero images by comparing file hashes and performing full raster decoding to catch truncated or stale assets that return a false HTTP 200 status.

Table of Contents1 sections
Crop unrecognizable female photographer editing photo while sitting at table with photo camera and graphic tablet during work in spacious room with flowerpots
Crop unrecognizable female photographer editing photo while sitting at table with photo camera and graphic tablet during work in spacious room with flowerpots.

A deployment might report a successful HTTP 200 status for a hero image, yet the file could be truncated, corrupted, or a stale version from a previous build. Relying on headers alone is insufficient because the server may return a complete status code even if the underlying byte stream is incomplete or incorrect.

Quick solution:

curl -s https://example.com/hero.jpg | sha256sum
# Validate the raster structure using ImageMagick
identify -verbose hero.jpg

To ensure your production assets match the approved source, you must move beyond metadata checks. While it is essential to Validate Raster Images in CI Beyond Metadata before deployment, you must also verify the final, publicly accessible bytes. A stale image might be perfectly valid in format but fail to match the expected fingerprint, while a truncated file will often fail during the decoding process.

Comparing Hashes for Integrity

To confirm the exact file is served, calculate the hash of the downloaded body and compare it against your known-good fingerprint. You can use the Node.js crypto.createHash API to automate this in a test suite. If the hash does not match, the asset is either stale or has been modified by an unintended process.

Decoding for Structural Validity

Even if the hash matches, you should perform a full decode to ensure the file is not truncated. The ImageMagick identify tool is effective here; it reads the image structure and will report an error if the file is incomplete or corrupt.

Interpreting Release Report Outcomes

When running these checks in a CI pipeline, your report should distinguish between three primary failure modes:

  1. Stale Asset: The hash comparison fails, but identify reports a valid image. This indicates the file is structurally sound but is not the version you approved.
    • Report Output: Expected: a1b2c3d4... Got: e5f6g7h8...
  2. Truncated Bytes: The hash comparison fails, and identify throws a decoding error. This confirms the file is incomplete.
    • Report Output: identify: Premature end of JPEG file
  3. Dimension Mismatch: The hash matches, but the image dimensions differ from your design specification. This often occurs when an optimization pipeline inadvertently alters the output.
    • Report Output: Expected: 1920x1080 Got: 1280x720

Release Verification Checklist

Continue Exploring

You Might Also Like

View all articles