Skip to content

Fix PostgreSQL binary-field corruption before encryption - #10

Merged
script3r merged 1 commit into
codex/share-keyset-primitivesfrom
codex/fix-binary-adaptation
Sep 5, 2026
Merged

Fix PostgreSQL binary-field corruption before encryption#10
script3r merged 1 commit into
codex/share-keyset-primitivesfrom
codex/fix-binary-adaptation

Conversation

@script3r

@script3r script3r commented Sep 5, 2026

Copy link
Copy Markdown
Owner

EncryptedBinaryField passed plaintext through the database driver's binary adapter before encryption. With psycopg this encrypted strings such as Binary(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 main as 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.

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.

1 participant