tclpdf 1.7.3 adds no feature. It closes one class of defect that no validator sees: a value of digits with a leading zero. The class has two halves. Tcl 8.6 reads 010 as octal 8 wherever it computes with it, Tcl 9 reads it as 10 — so a package that runs on both wrote two different files from the same input. And both interpreters turn a text that merely looks like a number into that number once it passes through an expr ternary: 0123 became 83 under 8.6 and 123 under 9.0, 1.10 became 1.1 under both. This note says what happened, how it showed, why eight review rounds and a green suite did not see it, and what changed.
What happened
Measured on Tcl 8.6.18 and 9.0.4, the same ten expressions:
| expression | 8.6.18 | 9.0.4 |
|---|---|---|
expr {010 + 1} |
9 | 11 |
expr {08} |
error, invalid bareword | 8 |
format %d 010 |
8 | 10 |
set n 010; incr n |
9 | 11 |
expr {"010" == 8} |
1 | 0 |
lsort -integer {010 9} |
010 9 |
9 010 |
expr {1 ? "0123" : ""} |
83 | 123 |
expr {1 ? "1.10" : ""} |
1.1 | 1.1 |
expr {1 ? "0x1A" : ""} |
26 | 26 |
scan 010 %d |
10 | 10 |
The first six are the octal half, and TIP 114 (written in 2007, delivered with Tcl 9.0) ends it. The next three are the other half, and Tcl 9 does not touch it: a ternary returns its branch as a number whenever the branch looks like one. Only scan %d reads the same under both.
How it showed
Example 05.04 with info Keywords "0123": the Info dictionary carried 0123, the XMP packet 83 under 8.6 and 123 under 9.0, and veraPDF reported PASS for PDF/A-3u although the two have to agree. A form field written as /T (010) came back from pdf fields as 8 or 10. A check box with the export value 01 set /V and /AS to 1. A certified document with /P 01 in its DocMDP dictionary was read as permission 1. A link address of digits reached /URI as a number. None of these is a malformed file; the wrong value is a valid one, which is why no validator objects.
How common the input is was measured too: of 27,170 PDFs in a corpus, 23 carry a number with a leading zero, 21 of them the package's own test probes, one a foreign test file, and one a real document, with /Length 0000001355. Leading zeros come from fields of fixed width — counters, offsets, dates — and from users who type them.
Why no check saw it
Norm review round 8 found the octal half in August, at eight places in the cross-reference structure of a foreign PDF, and those eight were fixed. Nobody turned the finding into a class. The review prompt never mentioned expr. No test had ever handed a string of digits to a text input: the test values were names, city, one, two and https://example.org. No lint rule and no skill named the trap. And the form that carries it, expr {[dict exists $d k] ? [dict get $d k] : {}}, looks like good style; it stood nine times in the tree of 1.7.2, the oldest from the second week of the project. Code and tests came from the same hand and shared the same blind spot.
What 1.7.3 changes
Two gates, and then the text. Numeric options go through one reader that takes a leading zero in decimal; the lexer that reads a foreign PDF does the same for every number in the file, so /Length, /Prev, /P and /BitsPerComponent mean the same under both interpreters. Every place that passed a text through a ternary — export values, link addresses, XMP texts, a font alias, field names, glyph bytes, charstring tables, the name of an unembedded font — take it by if/else instead, and each has a test that feeds 0123, 010, 1.10 or 0x1A and reads the file back.
The measuring found more than digits. stop-color in rgb() notation lost a whole SVG drawing; an exponent in a coordinate reached the content stream as it stood; the two XML parsers, tdom and the built-in one, answered the same broken file with different codes, and the built-in one accepted a bare &; the XMP packet set with metadata was parsed without the entity-expansion check every other XML gets; the first structure ... -script of a process evaluated its body in the wrong frame. All of it is in 1.7.3, each with its tests.
Against a return: a lint rule that reports the ternary form on every write, a review checkpoint that asks for the four probe values at every text input, and each new test proven by mutation — the old line put back, the test has to fall, under both interpreters.
What to do
Update. Nothing in the API changed; a caller who sets a field name, a keyword, an export value or a link of digits now gets it back as written, and a document written under 8.6 and under 9.0 is the same file again.
For Tcl code in general, three sentences hold under both interpreters. A value that is text never goes through expr, format %d, incr, lsort -integer or ==; it is passed with set and compared with eq. A number read from a file or a caller is read with scan %d before arithmetic. A ternary is for numbers; for anything else, if. Tcl 9 closes half of the trap, not the trap.