Fix bereal artifact #1638
Conversation
…Gear-I/iLEAPP into fix-bereal-artifact-errors-1497
abrignoni
left a comment
There was a problem hiding this comment.
Thanks for digging into #1497 — the crash fixes here are real and welcome: the os.path.isfile guard, skipping group.BeReal.plist in the JSON pass, the str(files_found) → str(file_found) bug, the early returns when bereal-chat.sqlite is missing, and initializing bereal_user_id/_bereal_processed at module level. 🙏
Three things need another pass before this can merge:
1. The owner id is never populated. process_bereal_preferences() now returns the owner id (nice refactor) — but all five call sites discard the return value, and nothing else assigns bereal_user_id. It stays None for the whole run, so format_userid(None) renders the literal string "Local User" for Accounts' author, Messages' recipient, and every owner that reads bereal_user_id. The actual user ID disappears from the output. See the inline comment on process_bereal_preferences for a small helper that fixes all five call sites at once (and also sets _bereal_processed = True, which currently is never set, so preferences re-parse for every artifact).
2. Owner attribution on other people's posts. In the series and production feed sections of RealMojis and Comments, the new code fetches get_user(series/post) and then overwrites the result with bereal_user_id. Those posts belong to other users — with this change they'd all be attributed to the device owner (and today, per item 1, to "Local User"). For a forensic report that's a misattribution, not just cosmetics. Inline suggestions restore the original get_user(...) attribution in those four spots. (The memories block is different — there is no per-post user there, and using bereal_user_id is exactly right once item 1 is fixed. That block just has a duplicated assignment to collapse.)
3. CI lint currently fails (9.96/10): duplicate-except ×2 in get_json_data (the combined clause re-catches JSONDecodeError/UnicodeDecodeError already handled above) and unused-variable ×2 for owner_user_name — both go away with the inline suggestions.
With those addressed this is a solid fix for #1497 and unblocks follow-up work on this file. Happy to re-review quickly.
…d)" from def bereal_chat_list(context): artifact
|
I've addressed the requested changes:
The latest commit includes all requested fixes. I'd appreciate another look when you have a chance. |
Summary
This PR fixes several BeReal artifact runtime issues reported in Issue #1497 and improves parser maintainability by removing module-level global state.
The changes prevent crashes when expected artifacts are missing, avoid parsing directories or binary plist files as JSON, fix BeReal owner resolution, and refactor preference handling so artifact state is locally scoped.
Changes
Prevented get_json_data() from attempting to parse directories.
Skipped group.BeReal.plist during JSON processing after it has already been handled by process_bereal_preferences().
Fixed undefined owner_user_name / owner resolution issues in BeReal Comments and related artifacts.
Prevented bereal_messages and bereal_chat_list from throwing exceptions when bereal-chat.sqlite is unavailable.
Removed module-level globals bereal_user_id and _bereal_processed.
Refactored process_bereal_preferences() to return the owner ID instead of modifying shared state.
Updated BeReal artifacts to use locally scoped owner/user state.
Addressed recent pylint findings, including broad exception handling and unused variables.
Results
Before this PR:
PermissionError occurred when directories were processed as files.
group.BeReal.plist caused UTF-8 decoding errors when parsed as JSON.
BeReal Comments could fail with an owner_user_name local variable exception.
BeReal Messages and Chat List could fail with NoneType.replace errors when bereal-chat.sqlite was missing.
The module relied on global state for BeReal owner handling.
After this PR:
All tested BeReal artifacts complete successfully.
Missing artifacts are handled gracefully.
Directory and plist handling no longer generate runtime exceptions.
Owner resolution is handled without module-level globals.
Existing artifact output is preserved where data is present.
Testing
Validated against:
Josh’s iOS 15 sample image
iOS 16.1.2 Cellebrite Full File System extraction
Confirmed the following artifacts complete without the previously reported runtime errors:
Notes
Additional validation with other BeReal acquisitions would still be helpful to confirm behavior across more app versions and datasets.
Fixes #1497.