Skip to content

Fix messageRetention losing the retention value on Windows - #1946

Merged
abrignoni merged 1 commit into
mainfrom
fix/messageretention-case-variant
Aug 13, 2026
Merged

abrignoni merged 1 commit into
mainfrom
fix/messageretention-case-variant

Conversation

@abrignoni

@abrignoni abrignoni commented Aug 13, 2026 •

Copy link
Copy Markdown
Owner

What was wrong

messageRetention declared two paths patterns differing only in case, and searched each
one separately with return_on_first_hit, labelling rows by which spelling it used:

"paths": ('*/mobile/Library/Preferences/com.apple.MobileSMS.plist',
          '*/mobile/Library/Preferences/com.apple.mobileSMS.plist'),

os.path.normcase folds case on Windows, so both patterns compile to the same thing and
both searches return the same first match. One file gets read twice and the other is
never read.

Both files really exist. This directory can hold com.apple.MobileSMS.plist and
com.apple.mobileSMS.plist as two different files, and 6 of the 20 local corpora that
carry this plist have both, from iOS 14.3 to 26.5.2. On all six the lowercase file held the
same three IMDCKBackupController* keys and no retention key.

Measured, before and after

Rows produced under each normcase regime, by patching scripts.search_files.normcase and
os.path.normcase and driving a real FileSeekerDir. AFTER is the pinned commit 0e2c563f.

configuration before (macOS / Windows) after (macOS / Windows)
only the uppercase file present 2 / 4 2 / 2
both files, case-insensitive output volume 3 / 2 3 / 1
both files, case-sensitive output volume 3 / 2 3 / 1

The bolded Windows numbers are the bug:

  • With one file, every row was emitted twice, half of them labelled
    com.apple.mobileSMS.plist, a filename not on the device. That is what a Windows
    validation sweep across 21 extractions was showing.
  • With both files, the two rows were both "No value": the real Keep Messages setting
    of "Forever" was lost outright, because both searches returned the 630-byte lowercase
    file and the 15 KB file holding the setting was never read. Which file wins depends on
    directory order.

macOS output is unchanged in all three configurations, so there is no regression on the
platform where it already worked.

The fix

One bracket class replaces the two patterns, and each spelling found is searched for and
read before the next is looked up. That ordering is load-bearing: the seeker copies
every match into the report's data/ folder, where the two spellings collide on a
case-insensitive volume and the second copy overwrites the first. Reading after all the
copying loses a file that reading between them keeps. Rows name the file actually read
rather than a hardcoded spelling.

Two smaller things in the same function:

  • A non-scalar value under either retention key went through dict.get, which raises on an
    unhashable value. It is now looked up only when it can be a key.
  • Rows are emitted in a fixed iOS <=16 then iOS 17+ order instead of the plist's own key
    order, which was never stable. Same rows, deterministic order.

Validation

Real ileapp.py profile runs against all 20 corpora that hold this plist, extracted to a
case-sensitive APFS volume so both files survive, run from a worktree pinned to the commit.
All 20 recorded sample_data counts reproduce exactly, 0 disagreements. Five corpora
that previously had no recorded count are added, and the six carrying both spellings are
annotated.

pylint --disable=C,R 10.00/10 (was 8.28), check_claim_language.py clean,
validate_sample_data.py 0 errors.

Known limitation, pre-existing and not fixed here

On a case-insensitive report volume the two copies collide under data/, so for one row the
preserved copy at the path shown holds the other file's bytes. The reported value is
correct, because each file is read before the next copy overwrites it, but an examiner
opening that path sees a file that does not support the row. Verified against unmodified
main as well: it behaves identically, so this is the seeker collision, not something this
change introduces. The artifact notes now say so explicitly.

An independent adversarial review of an earlier revision of this branch (aac07eec) flagged
the read-after-copy ordering as blocking, which is what prompted the current implementation;
its remaining findings were re-checked against 58ccf7f7 and either fixed or not reproduced.

Related

An AST sweep of __artifacts_v2__ paths tuples across all five LEAPP cores found exactly
two case-variant tuples: this one, and setupapiSections in DLEAPP's windowsSystem.py
(*/Windows/INF/setupapi.dev.log and */WINDOWS/INF/setupapi.dev.log). Independent
per-core review agents returned the same two. The DLEAPP one is left alone here.

Not fixed, and not an artifact-level problem: scripts/search_files.py copies each match
into data/ keyed by its path, so any two evidence files differing only in case collide
there and one silently overwrites the other. This artifact now works around it by reading
between copies; the general case would need a seeker change, which is opt-in in this repo.

Reported by Mattia Epifani.

Co-Authored-By: Claude Opus 5 [email protected]

The artifact declared two paths patterns differing only in case:

    '*/mobile/Library/Preferences/com.apple.MobileSMS.plist'
    '*/mobile/Library/Preferences/com.apple.mobileSMS.plist'

and searched each separately with return_on_first_hit, labelling rows by
which spelling it used. os.path.normcase folds case on Windows, so both
patterns compile to the same thing and both searches return the same
first match.

Both files really do exist. iOS APFS is case-sensitive, and 6 of the 20
local corpora that carry this plist hold both spellings as different
files, from iOS 14.3 through 26.5.2. The lowercase one holds iMessage
CloudKit backup keys, not a retention key.

So on Windows the artifact read one file twice and never read the other,
and which one it read depended on directory order. Demonstrated against
dexter_ios18's two plists by patching normcase and running a real
FileSeekerDir:

    only the uppercase file present
        before  macOS 2 rows, Windows 4 rows, every row duplicated and
                half labelled with a filename not on the device
        after   2 rows on both

    both files present
        before  macOS 3 rows correct, Windows 2 rows both "No value",
                the "Forever" setting lost entirely
        after   macOS 3 rows, Windows reports the one file the
                extraction preserved

One bracket class replaces the two patterns, and each spelling found is
searched for and read before the next is looked up. That ordering
matters: the seeker copies every match into the report data folder,
where the two spellings collide on a case-insensitive volume and the
second copy overwrites the first, so reading after all the copying
loses a file that reading between them keeps. Rows name the file
actually read rather than a hardcoded spelling.

Two smaller things in the same function: a non-scalar value under either
retention key went through dict.get and would raise on an unhashable
value, so it is now matched only when it can be a key; and rows are
emitted in a fixed iOS <=16 then iOS 17+ order rather than the plist's
own key order, which was never stable.

Validated with real ileapp.py profile runs against all 20 corpora that
hold the plist, extracted to a case-sensitive APFS volume so both files
survive. All 15 previously recorded sample_data counts reproduce
exactly, 0 disagreements. Five corpora that had no recorded count are
added.

Co-Authored-By: Claude Opus 5 <[email protected]>
@abrignoni
abrignoni force-pushed the fix/messageretention-case-variant branch from 0e2c563 to 58ccf7f Compare August 13, 2026 20:36
@abrignoni
abrignoni merged commit ec2f1d1 into main Aug 13, 2026
8 checks passed
@abrignoni
abrignoni deleted the fix/messageretention-case-variant branch August 13, 2026 20:43
abrignoni added a commit that referenced this pull request Aug 13, 2026
Two patterns in one `paths` tuple that differ only in case are two
patterns on macOS and Linux and one pattern on Windows, because
`os.path.normcase` folds case there. The entry point extends
`files_found` once per declared pattern with no dedup, and an artifact
that calls `seeker.search()` once per spelling gets the same first match
back from both calls, so one file is reported twice.

The worse outcome is that the second file, the one the duplicate pattern
was added for, is never read at all. That shipped in `messageRetention`
until #1946: both spellings of com.apple.MobileSMS.plist exist as
different files on 6 of the 20 local corpora carrying it, iOS 14.3
through 26.5.2, and on Windows the artifact read the 630-byte wrong one
twice and reported "No value" for a device whose Keep Messages setting
was "Forever". Nothing errored, rows were produced, and macOS output was
correct, so no sweep flagged it.

`check_artifact_paths.py` parses each module's `__artifacts_v2__`
literal, groups every `paths` entry by its Windows-folded form, and
fails on any group holding more than one spelling. It also fails on a
pattern repeated verbatim, which double-counts on every platform.

Discovery is recursive over `scripts/` rather than a
`scripts/artifacts/*.py` glob. Artifact modules also live in
`scripts/alternate_artifacts/`, which `--custom_artifacts_path` loads,
and in `scripts/test_artifacts/`; a directory-pinned glob misses those
today and would silently stop covering any directory added later.
Recursive discovery finds 843 tuples across 380 modules where the pinned
glob found 841 across 375. Modules whose block is not a static literal
are reported NOT CHECKED so the coverage hole stays visible, matching
check_claim_language.py.

`--self-test` runs the check against six known-bad and known-good
tuples, including the two real shapes this came from, so a checker that
silently stops matching cannot pass as a clean repo. Verified in both
directions against real code: restoring the pre-#1946 messageRetention
exits 1 and names both patterns; current main exits 0.

Wired into the existing lint workflow beside the other artifact guards,
and the rule is written into admin/docs/artifact_info_block.md next to
the normcase paragraph that already describes the mechanism.

Co-Authored-By: Claude Opus 5 <[email protected]>
abrignoni added a commit that referenced this pull request Aug 19, 2026
--list documented "print every paths tuple checked" and printed only a count
line that duplicated the summary. It now prints each module, artifact key and
its patterns. The count is derived from that same list, so the number reported
and the tuples printed cannot disagree.

Violations rendered an absolute path while the NOT CHECKED block used
os.path.relpath, so CI output carried the runner's directory. Both are
relative now.

Verified no verdict changed: the checker was run against iLEAPP and all four
sibling cores before and after, and the only difference in the output is the
DLEAPP violation path becoming relative. The self-test still passes, and
restoring the pre-#1946 messageRetention.py still exits 1.

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant