Cloud Optimized GeoTIFF Validator in Rust
Introduction
This project is a Cloud Optimized GeoTIFF (COG) validator implemented in Rust using GDAL. It checks compliance of GeoTIFF files with the COG specification, ensuring they are optimized for cloud storage and efficient access.
The validation logic mirrors rouault/cog_validator (the reference Python validator shipped with GDAL) and was initially inspired by cog-validator-java.
Features
- Supports GDAL Virtual File Systems: Validates local files and remote sources via
/vsicurl/,/vsis3/,/vsimem/, etc. - Warnings vs errors: Hard errors fail validation; soft issues (e.g. large image without overviews) are returned as warnings via
ValidationReport. - Configurable strictness through
ValidationOptions.
Validation Checks
File-level structure
- Driver must be
GTiff. - Overviews must be internal — no external
.ovrsidecar allowed. - Main IFD must be at offset
8(classic TIFF) /16(BigTIFF), or immediately after aGDAL_STRUCTURAL_METADATAblock aligned to a 2-byte boundary. GDAL_STRUCTURAL_METADATAblock is parsed for the flags:BLOCK_ORDER=ROW_MAJORBLOCK_LEADER=SIZE_AS_UINT4BLOCK_TRAILER=LAST_4_BYTES_REPEATEDMASK_INTERLEAVED_WITH_IMAGERY=YES
KNOWN_INCOMPATIBLE_EDITION=YESis rejected.
Image structure metadata
LAYOUT=COGis required (configurable, downgradable to warning).COMPRESSIONmust be one of:LZW,DEFLATE,ZSTD,LERC,LERC_DEFLATE,LERC_ZSTD,WEBP,JPEG,JXL,PACKBITS,CCITTFAX4.INTERLEAVEmust beBAND,PIXEL, orTILE.- Georeferencing (projection + geotransform) is required (configurable).
Main image / bands
- Images larger than 512 px in either dimension must be tiled.
- Tile dimensions must be multiples of 16.
- Large images without internal overviews produce a warning (configurable to error).
Overviews
- Overview dimensions must strictly decrease as the level index increases.
- Overview reduction factor (in both x and y) must strictly increase as the level index increases.
- Overview IFD offsets must be in increasing order.
- Each overview must be tiled.
- First data block of the smallest overview must be after its own IFD.
- For multi-overview files: data block of overview
imust be after data block of overviewi+1(smallest overview is written first). - First data block of the main image must be after the first data block of overview 0 (largest overview).
Per-block (when corresponding structural metadata flags are present)
BLOCK_LEADER=SIZE_AS_UINT4: the uint32 leader preceding each block must match its byte count.BLOCK_TRAILER=LAST_4_BYTES_REPEATED: the last 4 bytes of each block must be repeated as the trailing 4 bytes.BLOCK_ORDER=ROW_MAJOR: block offsets within a band must be non-decreasing in row-major order.
Mask bands
- Per-dataset mask bands are recursively validated.
- When
MASK_INTERLEAVED_WITH_IMAGERY=YES:- Mask block size must match the imagery band block size.
- For each block,
mask_offset == imagery_offset + byte_count + leader_pad + trailer_pad.
Requirements
- Rust toolchain
- GDAL library (installed separately)
Installation
Usage
Basic check (boolean result)
use cog_validator;
Detailed report with warnings
use ;
Configuring strictness
use ValidationOptions;
let options = ValidationOptions ;
| Option | Default | Effect |
|---|---|---|
require_cog_layout |
true |
Missing LAYOUT=COG is an error (otherwise warning). |
require_georeferencing |
true |
Missing projection or geotransform is an error (otherwise warning). |
require_internal_overviews_for_large_images |
false |
When true, large image without overviews is an error instead of a warning. |
License
Licensed under the Apache License 2.0. See LICENSE for details.
Acknowledgments
- rouault/cog_validator — the reference Python validator whose check semantics this project mirrors.
- cog-validator-java — the original inspiration.
- GDAL — geospatial data handling library this validator builds on.