]> git.ipfire.org Git - thirdparty/patchwork.git/commit
parser: Strip NUL bytes
authorStephen Finucane <stephen@that.guru>
Sat, 6 Jun 2026 11:33:39 +0000 (12:33 +0100)
committerStephen Finucane <stephenfinucane@hotmail.com>
Sat, 6 Jun 2026 11:58:58 +0000 (12:58 +0100)
commit758b99b149891e0e93caf0dc0f77475e3e4f4730
tree96a4d56ecca23f175e9e0c9bf8c6e59bf44c9672
parentde04e0aeffada0beade393d2c8c19c00904fffc3
parser: Strip NUL bytes

psycopg (v3) strictly rejects NUL bytes (0x00) in PostgreSQL text
fields, unlike psycopg2 which handled them silently. Malformed emails
(such as the codec-null.mbox fuzz fixture in our test suite) contain NUL
bytes in headers and body content, causing DataError on insert.

Strip NUL bytes from all text fields before they reach the database.
This is safe for all fields:

* Headers are restricted to printable ASCII by RFC 5322 meaning NUL
  bytes there always indicate corruption

* Email body / commit message content is plain text so NUL bytes are
  equally invalid here

* Unified diffs should also never contain NUL bytes. Git uses their
  presence as the heuristic to classify a file as binary, at which point
  it either emits 'Binary files ... differ' or, with --binary, a
  base85-encoded binary patch, both of which are entirely printable
  ASCII. A legitimate patch produced by git format-patch will therefore
  never carry NUL bytes in the diff text itself.

Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/parser.py