HomeBlogErlang ETF: What the Bytes Actually Say

Erlang ETF: What the Bytes Actually Say

I decoded 15 ETF test groups and traced a 29-byte compressed sample: exact tags, offset arithmetic, tested failures, and runtime boundaries.

DevKit is maintained by hcatree. I wrote the tools on this site and ran the compression benchmarks myself — the script and the raw data download from the benchmarks page.

2026-11-2712 min read

A compressed Erlang term can be completely decoded and still tell you almost nothing about the running system that produced it. The bytes can prove that a tuple contains atom ok and a three-byte binary. They cannot prove that a process is alive or a captured fun is safe to call.

ETF looks reassuringly typed: its tags name tuples, maps, binaries, references, and functions. But a type tag is not a runtime session. This article follows one compressed sample byte by byte, then compares it with DevKit's project-owned test suite.

First, define what “verified” means

I ran the repository's actual command:

npx tsx scripts/test-etf-wire.ts

It finished with this exact line:

15 ETF decoder test groups passed.

These are regression vectors for decodeEtf() in lib/etf-wire.ts, not an independent comparison against binary_to_term/1, an Erlang node, or another runtime. A green suite establishes no cross-runtime compatibility claim.

The normative reference is ERTS' External Term Format documentation. I checked the parser's tag numbers and field order against that document, then corrected the regression vectors to use the official encodings.

Version 131 is a gate, not a term

A standalone ETF term begins with version byte 131, hexadecimal 83. Empty input reports missing ETF version byte 131; byte 130 reports expected ETF version byte 131, found 130. Nested values do not repeat the version. In distribution traffic, ERTS can omit it when a distribution header supplies context, so a network capture is not automatically valid inspector input.

The compressed envelope, exactly

The built-in compressed sample is 29 bytes:

83 50 00 00 00 0f 78 9c cb 60 4a 61 60 ca cf ce 65
60 60 60 ce c8 fc 0f 00 1a 03 03 eb
Original offsets Bytes Meaning
[0,1) 83 ETF version 131
[1,2) 50 compressed tag 80
[2,6) 00 00 00 0f uncompressed size, four-byte big-endian: 15
[6,29) 78 9c … 1a 03 03 eb 23 bytes of zlib-compressed data

Thus 29 = 1 version + 1 tag + 4 size + 23 stream bytes. Tag 80 is top-level only. The payload contains consecutive term encodings without another 131.

The stream has zlib header 78 9c and a four-byte Adler-32 checksum. A bounded DEFLATE scanner finds its exact end; fflate then inflates and validates it. The declaration must equal the produced length.

Inflation produces exactly 15 bytes:

68 02 64 00 02 6f 6b 6d 00 00 00 03 68 69 ff

The decoded value is:

{"$tuple":["ok",{"$binary":"aGn/"}]}

aGn/ is Base64 for 68 69 ff: the bytes hi followed by ff. The wrapper is deliberate; treating those bytes as text would discard information.

Erlang ETF compressed offsets

One term, two coordinate systems

Inspector offsets are zero-based, half-open ranges. The tuple and both children share original-file span [1,29) because they came from one envelope. Their decompressed spans differ:

Node Original span Logical span in the 15-byte payload
Tuple [1,29) [0,15)
Atom ok [1,29) [2,7)
Binary hi ff [1,29) [7,15)

The arithmetic is 15 = 2 tuple-header + 5 atom + 8 binary. Header 68 02 means SMALL_TUPLE_EXT, arity two. The atom is 64 00 02 6f 6b; the binary is tag 6d, length 00 00 00 03, then 68 69 ff.

Compressed and decompressed bytes have no one-to-one mapping. An inner diagnostic therefore anchors to the original envelope and includes a logical offset in its message. logicalStart and logicalEnd are not file offsets.

A standard-zlib test vector produces consecutive terms 61 01 and 62 00 00 00 02, decoded as 1 and 2. Both share the envelope, with logical ranges [0,2) and [2,7). A following file term 61 09 becomes a third item, 9, with its own original range.

Raw DEFLATE is an extension, not the ETF standard

Standard compressed ETF requires a zlib wrapper. DevKit also accepts raw RFC 1951 DEFLATE for fflate deflateSync compatibility, emitting:

raw DEFLATE accepted for fflate deflateSync compatibility; standard ETF compression uses a zlib wrapper

This is an explicitly warned compatibility extension, not the standard ETF compressed representation.

The tags preserve distinctions that JSON normally loses

An atom is a name-like value, not an interned object here. 64 00 03 e9 fc f8 decodes as Latin-1 atom éüø; tag 115 is the one-byte-length Latin-1 SMALL_ATOM_EXT, while 119 is the corresponding UTF-8 form. Binary tag 109 carries arbitrary bytes. STRING_EXT (107) represents a list of byte-valued characters, not UTF-8 text: tested 107 0004 00 7f 80 ff retains all four bytes in $string.

Other tested distinctions:

  • SMALL_INTEGER_EXT (97) is signed 8-bit; INTEGER_EXT (98) is signed 32-bit big-endian.
  • NEW_FLOAT_EXT (70) is binary64; tests preserve π and negative zero as -0.
  • Big integers use little-endian magnitude plus sign 0 or 1. 18446744073709551616 stays exact in $bignum.
  • BIT_BINARY_EXT (77) records used bits; tests reject final-bit counts 0 and 9.
  • Tuples (104/105) retain arity, including a tested 256-element tuple.
  • LIST_EXT (108) has a tail; NIL_EXT (106) is empty. Improper lists retain elements and tail.
  • MAP_EXT (116) preserves wire order and duplicate encoded keys.

Typed JSON is inspection output, not a reversible encoder or runtime identity.

PIDs, ports, references, and funs are descriptions

The parser handles older PID (103), port (102), reference (101), and new-reference (114) layouts, plus modern NEW_PID_EXT (88), NEW_PORT_EXT (89), and NEWER_REFERENCE_EXT (90). It exposes node names, IDs, serials, creation values, and reference arrays. #PID<n@h.1.2> renders wire fields; it does not locate a live process or connect to n@h.

Function output is structural. Legacy FUN_EXT is tag 117; NEW_FUN_EXT is tag 112 and includes the creating Pid after OldIndex and OldUniq, before free variables. EXPORT_EXT is tag 113 and contains module, function, and arity. Tests cover free variables, the new-fun Pid field, and size overruns. Nothing executes a term or deserializes an arbitrary external fun into a live Erlang process.

Tag mappings checked against ERTS

The regression suite now uses the official mappings rather than a self-consistent but incorrect set:

  • ATOM_CACHE_REF is 82; 90 is NEWER_REFERENCE_EXT.
  • 115 is Latin-1 SMALL_ATOM_EXT; 119 is SMALL_ATOM_UTF8_EXT.
  • 112 is NEW_FUN_EXT, 113 is EXPORT_EXT, and legacy FUN_EXT is 117.
  • 106 is NIL_EXT; 108 is LIST_EXT.

These are specification checks, not runtime comparisons. Validate important captures with Erlang itself.

Why atom cache references need distribution context

An atom cache reference contains an index, not the atom's text. Its meaning depends on cache state associated with a distribution channel and its headers. The same small index can denote different atoms in different contexts, and an isolated term contains no authoritative cache contents.

DevKit therefore preserves its tested cache-reference vector as an unknown metadata node with a warning: ATOM_CACHE_REF 7 preserved as unknown; atom cache resolution requires distribution state. That is the honest result. Resolving it would require reconstructing distribution state, which this tool does not do. The tool also does not intern input atoms into a VM atom table.

The 15 test groups, without the marketing gloss

Every row below passed in the recorded run:

# Exact test-group name Evidence
1 small/integer/old float/new float scalars and exact spans Scalars, floats, spans
2 Latin-1 and UTF-8 atoms use their official tags and are not interned Encodings, distinct nodes
3 binary, bitstring and STRING_EXT typed wrappers Binary, bits, byte string
4 small/large tuples, proper/improper lists and ordered maps 256-tuple, tails, duplicate keys
5 signed bignums preserve values beyond Number precision Exact large integers
6 pid, port, references, export and both fun layouts use official tags Legacy/modern identifiers, exports, free variables
7 ATOM_CACHE_REF remains an unknown node with a warning Cache index 7
8 fflate deflateSync compressed vector has envelope spans and logical offsets Raw extension, child ranges
9 standard zlib vector, consecutive decompressed terms and following file terms Inner terms, file tail
10 compressed malformed terms preserve partial items and file-based diagnostics Partial inner tree
11 compression declarations, checksums, truncation and output cap fail safely Compression failures
12 compressed binaries may exceed the original-input cap within the output budget 2,000,001-byte binary
13 unknown tags, bad version and nested truncation yield error nodes/issues Tag 255, version 130, EOF
14 malformed UTF-8, bitstrings, bignum sign, map and new-fun size Eight malformed shapes
15 depth, container count, top-level item, node and input limits Resource boundaries

What malformed input actually does

Unknown tag 255 consumes only the version byte and reports unknown ETF tag 255 at offset 1. A truncated tuple retains decoded atom a and adds a child error, unexpected end of input.

The malformed sample declares a 32-byte binary without its body: binary length 32 overruns input by 32 byte(s). A map missing its value fails at EOF. A new fun declaring five body bytes with three available reports new fun size 5 overruns input by 2 byte(s).

Compression tests cover size mismatches, declarations above 20,000,000, streams 78 and ff, a flipped checksum byte, and excess expansion. Each produces a partial result with an error.

Input and decompressed-output limits are different

lib/wire-tree.ts limits original input to 2,000,000 bytes, enforced by Hex/Base64 parsing and upload. Oversized direct input reports input exceeds 2000000 bytes and consumes zero.

The output limit is 20,000,000 bytes, applied to declared uncompressed size, inner lengths, and scanner output. Inflation allocates declared + 1 to distinguish exact output from excess expansion. chargeTree() also charges an approximate report budget: 128 bytes per node, 12 per value character, plus Base64 and overhead for byte-bearing nodes. This exceeds a simple decompressed-byte count but shares the same ceiling.

A compressed binary with a 2,000,006-byte payload succeeds: its file is small and output is within budget. A bomb declaring 20,000,000 but expanding further fails with deflate output exceeds declared uncompressed size 20000000.

Other limits are 20,000 items, 50,000 nodes, 50,000 container entries, 256 levels, and 1,000 issues. The depth test accepts 256 and rejects 257. Limits produce partial decodes, not silent tree loss.

When this decoder is the right tool

Use the Erlang ETF Decoder for standalone term bytes, common tags, exact spans, binary/text distinctions, and parse diagnostics. It accepts Hex/Base64 and consecutive top-level terms, with typed JSON export.

Get more context for distribution headers, atom caches, fragmentation, clusters, tracing, or RPC. This tool does not intern atoms, reconstruct Erlang distribution sessions, connect to nodes, execute terms, load modules, or create processes from funs. Input stays in the browser; explicit share links contain the bytes, so share only non-sensitive captures.

A complete ETF tree proves a successful byte parse, not a recovered Erlang system.


References:

  • ERTS External Term Format — version 131, compressed layout, tag table, distribution headers, and atom-cache context.
  • fflate README — raw DEFLATE and zlib helper APIs used by the implementation and test vectors.

Environment: Node.js v24.22.0 on Windows x64, fflate 0.8.3, measured 2026-11-27. The Inspector column and diagnostics came from decodeEtf() in this repository, the same function used by the browser tool. All 15 groups were generated by npx tsx scripts/test-etf-wire.ts; these are project-owned spec vectors, not an independent Erlang runtime comparison.

Discuss this articleEchoForum · no sign-up, replies in any language

Related Tools

Erlang ETF DecoderDecode Erlang external terms & binaries
Binary Format DecoderInspect MessagePack, CBOR & BSON
Gzip / LZ4Gunzip Base64 or hex in one step