Inside an Avro Object Container File
A byte-level guide to Avro OCF headers, blocks, sync markers, codecs, CRC32 checks, exact spans, and malformed-input diagnostics in DevKit.
An Avro OCF can reveal every block boundary yet decode zero objects. Unsupported codecs preserve framing but hide datums; malformed schemas can leave a complete header and no block decode.
The question is not “can Avro be parsed?” but “which facts did these bytes establish?” I ran the Avro OCF Inspector against 17 project-owned test groups and its built-in 322-byte sample. This is an empirical reading of repository vectors, not an independent Avro runtime comparison.
The file is a header followed by self-synchronizing blocks
The Avro 1.11.0 specification defines magic, byte-valued metadata, and a 16-byte sync header. Each block carries count, size, payload, and repeated sync.
The sample has 322 bytes, one block, two objects, two tree nodes, codec null, zero errors. Its header occupies [0, 236) and block [236, 322). Ranges are half-open.
| File range | Bytes | Meaning |
|---|---|---|
[0, 4) |
4f 62 6a 01 |
Magic: ASCII Obj followed by byte 01 |
[4, 5) |
04 |
Metadata map block count: ZigZag long 2 |
[5, 17) |
16 + avro.schema |
Key length 11, then the key bytes |
[17, 19) |
f0 02 |
Schema value length: 184 bytes |
[19, 203) |
184 bytes | UTF-8 JSON writer schema |
[203, 215) |
14 + avro.codec |
Key length 10, then the key bytes |
[215, 219) |
08 + null |
Codec value length 4 and its bytes |
[219, 220) |
00 |
Zero-count metadata-map terminator |
[220, 236) |
00 01 … 0f |
Header sync marker |
[236, 237) |
04 |
Block object count: 2 |
[237, 239) |
86 01 |
Stored block size: 67 bytes |
[239, 306) |
67 bytes | Null-codec object payload |
[306, 322) |
00 01 … 0f |
Repeated block sync marker |
Complete verified sample:
0000 4f 62 6a 01 04 16 61 76 72 6f 2e 73 63 68 65 6d
0010 61 f0 02 7b 22 74 79 70 65 22 3a 22 72 65 63 6f
0020 72 64 22 2c 22 6e 61 6d 65 22 3a 22 4d 65 73 73
0030 61 67 65 22 2c 22 6e 61 6d 65 73 70 61 63 65 22
0040 3a 22 65 78 61 6d 70 6c 65 22 2c 22 66 69 65 6c
0050 64 73 22 3a 5b 7b 22 6e 61 6d 65 22 3a 22 69 64
0060 22 2c 22 74 79 70 65 22 3a 22 6c 6f 6e 67 22 7d
0070 2c 7b 22 6e 61 6d 65 22 3a 22 74 65 78 74 22 2c
0080 22 74 79 70 65 22 3a 22 73 74 72 69 6e 67 22 7d
0090 2c 7b 22 6e 61 6d 65 22 3a 22 74 61 67 73 22 2c
00a0 22 74 79 70 65 22 3a 7b 22 74 79 70 65 22 3a 22
00b0 61 72 72 61 79 22 2c 22 69 74 65 6d 73 22 3a 22
00c0 73 74 72 69 6e 67 22 7d 7d 5d 7d 14 61 76 72 6f
00d0 2e 63 6f 64 65 63 08 6e 75 6c 6c 00 00 01 02 03
00e0 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 04 86 01 54
00f0 18 48 65 6c 6c 6f 2c 20 41 76 72 6f 21 04 0a 6c
0100 6f 63 61 6c 0e 62 72 6f 77 73 65 72 00 82 80 80
0110 80 80 80 80 20 1e e7 ac ac e4 ba 8c e6 9d a1 e6
0120 b6 88 e6 81 af 04 0c e4 b8 ad e6 96 87 06 4f 43
0130 46 00 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d
0140 0e 0f
avro.schema is required; avro.codec defaults to null. Metadata values are arbitrary bytes, but schema and codec values must be valid UTF-8 here. Real files normally use random sync markers; this sample uses sequential bytes.
Avro long: ZigZag first, varint second
Avro longs use ZigZag coding, then write the unsigned result as little-endian seven-bit groups. Continuation bit 1 means another byte follows.
| Value | ZigZag unsigned | Encoded bytes |
|---|---|---|
0 |
0 | 00 |
-1 |
1 | 01 |
1 |
2 | 02 |
42 |
84 | 54 |
67 |
134 | 86 01 |
9007199254740993 |
18014398509481986 | 82 80 80 80 80 80 80 20 |
Thus 04 means positive 2, while block size 86 01 means 67.
The format permits a negative OCF block count: its absolute value is the object count, followed by a long byte size for skipping without decompression. Thus 03 means -2, then the size. The Inspector instead passes the raw count to a nonnegative counter and rejects it with container count exceeds 50000; this branch is not implemented. Negative metadata, array, and map counts are separate, supported, tested cases.
Codec decisions change what “size” means
The block size describes the stored payload, excluding count, size, and trailing sync fields—not the decompressed byte count. Snappy’s stored payload includes its four CRC bytes.
One-byte long = 42 probe; not a compression benchmark.
| Codec | Spec status | Inspector behavior | Stored payload | Decompressed object bytes |
|---|---|---|---|---|
null |
Required | Decode | 54 — 1 byte |
1 byte |
deflate |
Required | Decode raw RFC 1951 | 0b 01 00 — 3 bytes |
1 byte |
snappy |
Optional | Validate framing, decompress, verify CRC32 | 01 00 54 be 04 7a 60 — 7 bytes |
1 byte |
bzip2 |
Optional | Skip block; report error | Not decoded | Unavailable |
xz |
Optional | Skip block; report error | Not decoded | Unavailable |
zstandard |
Optional | Skip block; report error | Not decoded | Unavailable |
| Unknown name | Not an Avro codec | Skip block; report error | Not decoded | Unavailable |
null consumes zero bytes for an Avro null datum and otherwise passes bytes through. deflate is raw RFC 1951 without a checksum, not a gzip wrapper. Compression makes this one-byte probe larger; that says nothing about general ratios or speed.
Snappy appends a four-byte, big-endian CRC32 of uncompressed data. Here be 04 7a 60 checks byte 54, and expected equals computed. A bad checksum yields error; unsupported codecs yield skipped, without data or objects.
Schema parsing is not datum decoding
The implementation first decodes avro.schema as UTF-8 JSON and validates its schema graph; only then does it decode block datums.
Supported branches include primitives, records, enums, fixed, arrays, maps, unions, named references, namespaces, and recursive records. Invalid branches become diagnostics: unknown names, empty or duplicate unions, nested unions, invalid names, and invalid fixed sizes. Missing avro.schema is also an error. headerComplete describes framing, not successful decoding.
Logical annotations may have an underlying representation this tool can display, but it does not implement every Avro logical type. It does not write OCF files; the internal sample builder only supplies demonstration input. The product workflow is inspection, copying, and downloading decoded output.
Exact spans prevent a subtle offset lie
Both sample objects share original-file span [239, 306) but have different ranges inside the 67 decompressed bytes:
| Object | Original-file span | Logical span | Decoded value summary |
|---|---|---|---|
| 0 | [239, 306) |
[0, 30) |
id = 42, text Hello, Avro!, tags local, browser |
| 1 | [239, 306) |
[30, 67) |
id = "9007199254740993"; UTF-8 text and tags follow |
Datum nodes keep start/end for the original payload and logicalStart/logicalEnd within decompressed data. Deflate and Snappy have no one-to-one datum-to-compressed-byte mapping, so the Inspector separates these views. Diagnostics retain relevant logical offsets rather than presenting them as file offsets.
Exported JSON uses typed wrappers where plain JSON loses information:
- Integers outside JavaScript’s safe range become decimal strings, preserving
9007199254740993exactly. - Bytes, fixed values, metadata values, and sync markers use
{ "$binary": "…" }with Base64 content. Test bytes00 ff 01become{ "$binary": "AP8B" }. - Non-finite floats and negative zero use
{ "$float": "…" }, includingNaN,Infinity,-Infinity, and-0. - Unions use
{ "$union": type, "value": … }, so the selected branch remains explicit. - Maps use
{ "$map": [[key, value], …] }, preserving entry structure instead of flattening it into an ordinary object.
These wrappers are output contracts, not decoration.
What the malformed vectors actually do
These are real decoder outcomes from the suite’s malformed vectors; only the JSON parser’s variable location text is shortened.
| Test case | Observed result |
|---|---|
Missing avro.schema |
Header complete; required Avro metadata key avro.schema is missing |
Schema value { |
Header complete; avro.schema is not valid JSON: … |
Reference to missing.Type |
invalid avro.schema: unknown Avro named type missing.Type |
Union ["null", "null"] |
invalid avro.schema: duplicate Avro union branch null |
Fixed size -1 |
Avro fixed size must be between 0 and 20000000 |
| Truncated header, payload, sync, or datum | Error and partial = true; overruns name the missing byte count |
| Block sync differs from header sync | Block skipped; block sync marker mismatch; block skipped |
Snappy block with stored CRC 0 |
Block error; CRC valid = false; zero objects decoded |
| Two null objects plus one trailing byte | Block partial; 1 trailing decompressed byte(s) after 2 objects |
| Snappy declares one byte but copy tags expand past it | Block error before library decompression: Snappy block expands beyond its declared or allowed length |
Block status is nuanced: decoded consumes exactly the declared objects; partial stops after a datum or trailing-byte failure; skipped retains framing without decoding; error fails payload processing before any object is decoded.
The 17-group verification run
All 17 groups passed with npx tsx scripts/test-avro-ocf-wire.ts, ending in 1..17. These project-owned implementation vectors are not an independent Avro conformance suite.
| Groups | Coverage checked |
|---|---|
| 1 | CRC32 of 123456789 equals 0xcbf43926 |
| 2–3 | Null-codec datums, namespaces, wrappers, logical offsets, and independent multi-block spans |
| 4–6 | Raw deflate, Snappy CRC, negative-count collections, and qualified names |
| 7–9 | Sync mismatch, CRC mismatch, and unsupported codecs never claimed as decoded |
| 10–12 | Malformed schemas, truncation, invalid primitives, enum/union indices, UTF-8, and trailing bytes |
| 13–15 | Input/output/count/node/depth limits, bad magic, malformed compressed streams, and Snappy framing |
| 16 | Decompressed data may exceed the original-input cap while remaining within the output budget |
| 17 | Deep invalid schemas remain diagnostic and safe to serialize |
Limits are 2,000,000 input bytes, 20,000,000 output bytes, 50,000 nodes, 20,000 items, 50,000 collection entries, and depth 256. Deflate preflights with bounded retention; Snappy validates expanded length and copy commands first. A 20,000,001-byte expansion fails the output bound. A valid deflate datum may still exceed the input cap within the output budget.
Try it without uploading the file
Open the Avro OCF Inspector, paste hex/Base64, or choose a local .avro, .ocf, or .bin file. Parsing stays in-browser. Block rows separate declared/decoded objects, stored/decompressed sizes, status, and CRC; byte views preserve both offset systems.
Share links contain original input: use non-sensitive data. Adjacent tools: Binary Decoder and JSON Formatter.
References:
- Apache Avro 1.11.0 specification — object container files, binary encoding, and codecs
- RFC 1951 — DEFLATE compressed data format
Environment: Node.js v24.22.0, Windows x64, verified 2026-11-27 with npx tsx scripts/test-avro-ocf-wire.ts. Sources: lib/avro-ocf-wire.ts, components/AvroOcfInspector.tsx, scripts/test-avro-ocf-wire.ts.