Skip to content

Conversation

@Tokenzrey
Copy link

@Tokenzrey Tokenzrey commented Dec 8, 2025

This PR fixes a critical bug in mailprotect.py that causes the artifact parser to crash when processing iOS < 13 Mail data.

The crash was caused by a redundant db.close() statement. Since the database is opened using a context manager (with open_sqlite_db_readonly...), the connection is automatically closed when the block exits. The explicit close call was creating a race condition or invalid state, leading to sqlite3.ProgrammingError: Cannot operate on a closed database.

Changes

  • Removed: Redundant db.close() statement in mailprotect.py.
  • Result: The parser now relies entirely on the context manager for resource cleanup, adhering to PEP8 best practices and preventing the crash.

Verification & Testing

I have created a reproduction script (test_mailprotect_fix.py) to verify the fix.

  • Test Suite: 5/5 tests passed.
  • Scenarios Covered:
    • Context Manager Lifecycle.
    • Multiple Queries within the same context.
    • Cursor recreation patterns.
    • Transaction handling.
    • Comparison of Original (Buggy) vs. Fixed patterns.

Test Output Summary:

TEST SUMMARY
================================================================================
Context Manager Lifecycle......................... [PASS]
Multiple Queries Within Context................... [PASS]
Cursor Recreation Pattern......................... [PASS]
Transaction Handling.............................. [PASS]
Original vs Fixed Pattern......................... [PASS]
================================================================================
Total: 5/5 tests passed
[SUCCESS] ALL TESTS PASSED - Fix is working correctly!

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.

Related Issues

Closes #1386

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.

[Bug] sqlite3.ProgrammingError in mailprotect.py during iOS < 13 artifact parsing

1 participant