Skip to content

Conversation

@Tokenzrey
Copy link

@Tokenzrey Tokenzrey commented Dec 8, 2025

This PR fixes a critical bug in ConnectedDeviceInformation.py where the parser would crash when encountering invalid, corrupt, or non-SQLite files that matched the healthdb*.sqlite filename pattern.

Previously, the script assumed 100% file integrity. If sqlite3 raised a DatabaseError (e.g., "file is not a database"), the exception was unhandled, leading to a complete failure of the artifact extraction. This update implements defensive programming to handle these scenarios gracefully.

Changes

  • Added: try-except blocks around get_sqlite_db_records() calls in:
    • connected_device_info_device_history
    • connected_device_info_consolidated_connected_device_history
    • connected_device_information_current_device_info
  • Logic: If an exception occurs during the query, the error is logged via logfunc, and db_records is set to an empty list. This allows the function to return a valid report structure (with zero records) instead of crashing.
  • Result: The parser is now resilient to corrupted healthdb files and preserves the stability of the extraction process.

Verification & Testing

I have created a comprehensive test suite (test_connected_device_fix.py) to verify the fix and ensure no regressions.

  • Test Suite: 5/5 tests passed.
  • Scenarios Covered:
    • Text File with .sqlite Extension: Simulates a file with the correct name but invalid content.
    • Corrupted SQLite File: Simulates a database with a broken header.
    • Graceful Error Handling: Verifies the wrapper catches the error and returns empty lists.
    • Valid Database Regression: Ensures valid databases still process correctly.
    • Exception Type Verification: Confirms DatabaseError is properly identified.

Test Output Summary:

TEST SUMMARY
================================================================================
Text File with .sqlite Extension.................. [PASS]
Corrupted SQLite File............................. [PASS]
Graceful Error Handling........................... [PASS]
Valid Database Regression......................... [PASS]
Exception Type Verification....................... [PASS]
================================================================================
Total: 5/5 tests passed
[SUCCESS] ALL TESTS PASSED - ConnectedDeviceInformation fix is working!

Checklist

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have verified the fix with a local test script.
  • The changes generate no new warnings.

@stark4n6
Copy link
Collaborator

@Tokenzrey if you're using logfunc function throughout the script why not just import once instead of 3 times?

@JamesHabben
Copy link
Collaborator

The exceptions are too general and will override basic exceptions, and this will cause lint errors. The duplicate imports are unnecessary and will als cause lint errors.

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.

3 participants