fix: accept any second byte in searched in-object strings

The byte after the string tag is a script code in some strings, not
always 0. Read a layer name at offset 19 of chunk 0x304 when the tag is
there, accept any second byte in find_string and in the style GUID
pattern. Evidence in objects.md.

compare.py --exclude own/, trustworthy pairs: coverage 98.10 % ->
98.11 % (+912 values): Layer Name 188 wrong -> 0, StyleUniqueId +479
paragraph and +245 character styles, 4 more styles whose IDML GUID
differs from the stored one (a known kind). All pairs 96.24 % ->
96.25 %. Extras unchanged (8,968), no new failures or warnings, schema
failures 0 on pairs.

diff_outputs.py: 383 outputs differ: 455 layer names that were empty
now have their name (346 files), and 1,538 styles gain StyleUniqueId.
No other change.
This commit is contained in:
aiongg committed 2026-10-08 16:27:10 +00:00
1 parent c43a16815b
commit 3a8718d9db
4 files changed
+47 -12

No files matched your search

+19 -4
View File
@@ -45,8 +45,8 @@ are in `big-endian.md`.
UTF-16 code units follow. A text of *n* code units is a sequence of
segments adding up to *n*. Example: "WOMEN’S\r" is
`05 40 "WOMEN" 01 80 19 20 02 40 "S\r"`.
- **In-object strings:** u8 2, u8 (usually 0, meaning unknown), u16 length
in code units, then segments. 4,135 occurrences in three sample files.
- **In-object strings:** u8 2, u8 (usually 0; a script code in some
strings, below), u16 length in code units, then segments. 4,135 occurrences in three sample files.
In files from InDesign 2.0 the first byte is 1: in the four distinct 2.0
files, the pattern tag, 0, length *n*, 0, segment header 0x4000 + *n*
occurs 154 to 353 times per file with tag 1 and never with tag 2. In
@@ -84,6 +84,12 @@ users of a document have the same byte, except in one pair with users
of bytes 0 and 7. The converter uses the byte of the last user to
choose font family names (`fonts.md`, native family names).
Other in-object strings carry the same kind of byte, so a search for a
string must accept any second byte. In the 149 pairs typeset in
Japanese it is 1 for most user-made names, and 3, 5, 7, 0x19 and 0x1D
also occur, in style names, style GUIDs, layer names and ruby font
styles. Layer names and style GUIDs (below) rely on this.
**Document users.** IDML lists one `DocumentUser` per user in chunk
0xA443, `Self` being `dDocumentUser` and the index in hexadecimal (491 of
495 trustworthy pairs have as many users as the chunk; the other 4 are
@@ -328,7 +334,12 @@ trustworthy pairs that layer is not written. It is usually named
name (2), so the name does not identify it. In all 1,053 layers of the trustworthy pairs the name starts at
offset 19, and each field above equals the IDML value for 1,053 of 1,053
layers (127 locked, 55 hidden, 59 not printable, 4 with locked guides,
1 without `UI`, 2 ignoring text wrap). `ShowGuides` and `Expendable` are
1 without `UI`, 2 ignoring text wrap). In the corpus of 2026-10, the
string at offset 19 gives the IDML `Name` of 1,683 of 1,683 layers in
all pairs, whatever its second byte (in the trustworthy pairs, 188
layers have a byte other than 0, all with the IDML name). The converter reads the name at offset 19 when byte
19 is the string tag, and otherwise searches for a string from offset
18. `ShowGuides` and `Expendable` are
true in every layer; the two fields that are 1 in every sample may hold
them. The converter reads the fields only when the name starts at offset
19 (in all little-endian corpus pairs, 1,465 layers).
@@ -1591,7 +1602,11 @@ is a 36-character in-object string after the name; where it is stored,
IDML has it as `StyleUniqueId` in 2,769 of 2,793 styles (DOM 11 on; the
other 24 have another GUID in IDML). Styles without a stored GUID
(1,108 from DOM 11 on) have a `StyleUniqueId` in IDML that the INDD does
not hold, which the converter leaves out.
not hold, which the converter leaves out. The byte after the GUID's
string tag is not always 0. In the trustworthy pairs of the corpus of
2026-10, accepting any second byte gives 724 more styles (479
paragraph, 245 character) the IDML `StyleUniqueId`; 4 more have another
GUID in IDML, as above.
**Kind field.** The kind and the `Imported` u16 after it can be read
as one u32 in most files, because the second u16 is 0. The InDesign 7.5
+6 -2
View File
@@ -314,8 +314,12 @@ impl<'a> Reader<'a> {
let locked = c.u16()? != 0;
let visible = c.u16()? != 0;
c.skip(14)?;
// A string follows; its position varies, so search for the tag.
let name = find_string(self.enc(), &data, 18)?;
// A string follows, at offset 19 in all corpus pairs; elsewhere
// search for the tag (objects.md, layers).
let name = match data.get(19) {
Some(2) if !self.enc().big_endian() => self.cursor(&data[19..]).string()?,
_ => find_string(self.enc(), &data, 18)?,
};
let settings = self.layer_settings(&data)?;
Ok(Layer {
uid,
+18 -2
View File
@@ -30,7 +30,9 @@ pub(super) fn find_flagged_string(
})
}
/// Find the first in-object string at or after `from`.
/// Find the first in-object string at or after `from`. The byte after
/// the tag can have any value (`docs/format/objects.md`, in-object
/// strings).
pub(super) fn find_string(enc: Encoding, data: &[u8], from: usize) -> Result<String, Error> {
if enc.big_endian() {
// The tag (2), the byte before it in little-endian data, then the
@@ -47,7 +49,7 @@ pub(super) fn find_string(enc: Encoding, data: &[u8], from: usize) -> Result<Str
return Ok(String::new());
}
for i in from..data.len().saturating_sub(4) {
if data[i] == 2 && data[i + 1] == 0 {
if data[i] == 2 {
let n = enc.u16_from([data[i + 2], data[i + 3]]) as usize;
if n > 0
&& i + 6 <= data.len()
@@ -60,3 +62,17 @@ pub(super) fn find_string(enc: Encoding, data: &[u8], from: usize) -> Result<Str
}
Ok(String::new())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn finds_strings_with_any_second_byte() {
let enc = Encoding::default();
for second in [0, 1, 0x19] {
let d = [9, 9, 2, second, 2, 0, 2, 0x40, b'a', b'b'];
assert_eq!(find_string(enc, &d, 0).unwrap(), "ab");
}
}
}
+4 -4
View File
@@ -159,14 +159,14 @@ impl<'a> Reader<'a> {
} else {
None
};
// A 36-character in-object string after the name: a GUID.
const GUID: [u8; 6] = [2, 0, 36, 0, 36, 0x40];
// A 36-character in-object string after the name: a GUID. The
// byte after the tag can have any value (objects.md, styles).
let unique_id = if self.enc().big_endian() {
None
} else {
data[at..]
.windows(GUID.len())
.position(|w| w == GUID)
.windows(6)
.position(|w| w[0] == 2 && w[2..] == [36, 0, 36, 0x40])
.and_then(|i| self.cursor(&data[at + i..]).string().ok())
};
let attrs = match self.chunk(uid, chunk::STYLE_ATTRS)? {