The container¶
Both kinds of library file, the manifest and the partition, are containers: a fixed header, a list of tagged sections, and a SHA-256 digest of everything before it. The container checks integrity and framing only; the sections' contents are specified on the partition and manifest pages. The design is ST1.3.
Layout¶
| Offset | Size | Field | Value |
|---|---|---|---|
| 0 | 4 | magic | the ASCII bytes JDGB (4a 44 47 42) |
| 4 | 4 | format version | u32 2 |
| 8 | 4 | termbank format |
u32 2 |
| 12 | 4 | kernel commit length | u32 40 |
| 16 | 40 | kernel commit | 40 ASCII hexadecimal digits, 0–9, a–f, A–F |
| 56 | 1 | kind | u8: 4 manifest, 6 partition |
| 57 | 4 | section count | u32 |
| 61 | … | sections | for each: tag u32, length u64, then that many payload bytes |
| \(L - 32\) | 32 | digest | SHA-256 of bytes \(0\) to \(L - 33\) |
\(L\) is the file's length. The header is 61 bytes, so the smallest container, with no sections, is 93 bytes. Section \(i\)'s tag is at offset \(61 + \sum_{j < i} (12 + \ell_j)\), where \(\ell_j\) is section \(j\)'s length, and its payload starts 12 bytes later.
The kernel commit names the writer's kernel revision. It is recorded
verbatim and never compared: a reader's own checker checks everything. A
reproducing writer writes the commit of the files it reproduces; the
reference writer writes the fixed commit
75e6f10571889b69f37ab91c16181f80f00a885a.
Kinds and sections¶
| Kind | File | Allowed tags | Required |
|---|---|---|---|
| 4 | manifest (.jlm) |
1–8 | 1–8 in library format 2.2, each exactly once |
| 6 | partition (.jlp) |
1–10 | all ten, each exactly once |
Every other kind is unknown and refused (FORMAT at 56).
Sections appear in strictly
increasing tag order, so each tag at most once. The container layer admits a
subset of the allowed tags; the manifest and partition readers then require
theirs (a partition reader refuses a missing section with FORMAT at byte
57; the manifest reader refuses one with FORMAT).
Limits¶
A reader takes three limits:
| Limit | Default | Library use |
|---|---|---|
max_bytes: the container's whole length |
67,108,864 (64 MiB) | the default, for manifests and partitions |
max_section_bytes: one payload's length |
67,108,864 | the default, for manifests and partitions |
max_sections |
9 | a manifest: 9; a partition: 10 |
The reference writer writes manifests and partitions with the default byte
limits, so every library file is at most 64 MiB, and refuses (LIMIT) a
section or file that would exceed them, counting the 32-byte digest before it
adds a section. A partition that would exceed them is cut again
(sub-partitions). In a partition,
max_section_bytes also bounds each compressed section's raw length
(partitions).
Reading¶
A reader validates in this order and refuses at the first failure. Every offset is zero-based in the file.
| Step | Check | Refusal |
|---|---|---|
| 1 | the limits are nonnegative | LIMIT, no offset |
| 2 | \(L \le\) max_bytes |
LIMIT at 0 |
| 3 | \(L \ge 93\) | FORMAT at \(L\) |
| 4 | magic is JDGB |
FORMAT at 0 |
| 5 | format version is 2 | FORMAT at 4 |
| 6 | termbank format is the reader's own (2) |
VERSION at 8 |
| 7 | commit length is 40 | FORMAT at 12 |
| 8 | each commit byte is a hexadecimal digit | FORMAT at that byte, \(16 + i\) |
| 9 | kind is 4 or 6 | FORMAT at 56 |
| 10 | section count \(\le \lfloor (L - 32 - 61) / 12 \rfloor\) | FORMAT at 57 |
| 11 | section count \(\le\) max_sections |
LIMIT at 57 |
| 12 | for each section in order: the tag is allowed for the kind and greater than the previous tag | FORMAT at the tag |
| 13 | the length is at most the bytes left before the digest | FORMAT at the length field (tag + 4) |
| 14 | the length is at most max_section_bytes |
LIMIT at the length field |
| 15 | the last section ends exactly at \(L - 32\) | FORMAT at the first extra byte |
| 16 | the digest equals SHA-256 of bytes \(0\) to \(L - 33\) | DIGEST at \(L - 32\) |
An unsupported container version is refused at byte 4. Structural errors are
reported before a bad digest. A reader MUST check a length against the bytes
that remain before converting it to a machine integer, and MUST NOT read past
\(L - 32\) while parsing sections. Asking a valid container for an absent
section is a caller error (FORMAT without an offset).
The reference reader also charges a work budget (the input length before
validation, and again before keeping a copy); exhausting it is LIMIT at 0.
Other implementations SHOULD bound their work by the input length in the same
way.
Writing¶
A writer writes the header with version 2, termbank format 2, the commit
length 40, its commit, the kind, and a placeholder section count; appends each
section as its tag (u32), its length (u64), and its payload, in strictly
increasing tag order; then patches the count at offset 57 and appends the
SHA-256 of everything written. The container has no padding, alignment, or
timestamps, so equal sections give equal bytes.
An example¶
The smallest valid partition envelope has ten empty sections. Its first 61 bytes, with the reference writer's commit:
00000000 4a 44 47 42 02 00 00 00 02 00 00 00 28 00 00 00 |JDGB........(...|
00000010 37 35 65 36 66 31 30 35 37 31 38 38 39 62 36 39 |75e6f10571889b69|
00000020 66 33 37 61 62 39 31 63 31 36 31 38 31 66 38 30 |f37ab91c16181f80|
00000030 66 30 30 61 38 38 35 61 06 0a 00 00 00 |f00a885a.....|
Each section then takes 12 bytes, 01 00 00 00 and eight zero bytes for tag
1, and so on, followed by the 32-byte digest. (No partition reader accepts
those empty payloads: every compressed section needs its raw length and a
stream, and the directory its root.)
The publication page has a program that
writes and reads a container with ContainerWriter and ContainerReader.