Fix PostgreSQL binary-field corruption before encryption - #10
Merged
script3r merged 1 commit intoSep 5, 2026
Merged
Conversation
This was referenced Sep 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
EncryptedBinaryFieldpassed plaintext through the database driver's binary adapter before encryption. With psycopg this encrypted strings such asBinary(b'original\\x00\\xff'), so reads returned corrupted content; memoryview inputs could lose their content entirely in the adapter representation.Convert buffer inputs directly to bytes and apply the database adapter only to final ciphertext. Add psycopg to the test extra so CI exercises the real PostgreSQL adapter without requiring a server. Runtime dependencies are unchanged.
Validation: 4 real-driver regression cases failed before the fix. All 120 library and 6 example tests pass on Python 3.14 / Django 6.0 / Tink 1.16.1 and Python 3.10 / Django 5.2 / Tink 1.13.0. Covers bytes, bytearray, memoryview, empty buffers, nulls, invalid inputs, and raw SQLite ciphertext. Ruff lint/format and Pyright pass. This is driver-level PostgreSQL testing, not server integration.
Existing correctly stored ciphertext remains readable. Already-corrupted rows need application-specific recovery; the fix cannot reconstruct bytes that were never encrypted.
Stack position: 4 of 6; depends on #9. Land predecessors first and retarget to
mainas needed.Landing order: #7 → #8 → #9 → #10 → #11 → #12.
Full review and landing notes. Use merge commits to preserve stack ancestry; squash/rebase merges require rebasing the remaining stack before landing it.