Fix Parser Crashes for Wire Messenger, Firefox, and Android Notification History #628
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses distinct issues causing parser crashes across three different artifacts during analysis:
Firefox Artifacts: Fixes a sqlite3.OperationalError caused by schema version mismatches where the moz_places_metadata table is missing.
Android Notification History: Fixes an xml.etree.ElementTree.ParseError caused by residual "junk" data at the end of XML files and corrects logic flow to prevent incorrect parser selection.
Wire Messenger: Fixes an AttributeError crash caused by the parser erroneously identifying cache files as SQLite databases.
Changes
Schema Validation: Introduced a table_exists() helper function to verify the presence of moz_places_metadata and moz_places_metadata_search_queries before execution.
Dynamic Querying: Implemented conditional logic to switch between a full query (with metadata) and a fallback query (without metadata) depending on the database version. This prevents the parser from crashing on older or different versions of Firefox where specific tables are absent.
XML Sanitization & Recovery: Added try-except ET.ParseError blocks for settings_secure.xml and notification_policy.xml. If parsing fails due to junk data (slack space) after the closing tag, the script now reads the file as a raw string, identifies the valid closing tag (e.g., ), and trims the residual data before re-parsing.
Logic Flow Correction: Changed the if statement to elif for the notification_policy.xml check. This ensures mutually exclusive execution paths, preventing XML files from being erroneously processed by the Protobuf parser in the else block.
Database Validation: The parser previously attempted to open any file ending in the User ID UUID, leading it to process non-database cache files. Modified get_user_database to explicitly ignore /cache/ directories and validate the file header for SQLite format 3 bytes before accepting it.
Null Safety: Added checks (if not user_database) in the main processing functions to ensure a valid database path was returned. This prevents the AttributeError: 'NoneType' object has no attribute 'cursor' crash when no valid DB is found or if the file cannot be opened.
Before the Bug Fix:
After the Bug Fix: