Skip to content

v3.1.1: fix result writer overflow (GHSA-4qp2-3768-j99g) and other v3.1.0 defects - #39

Merged
bjfultn merged 4 commits into
mainfrom
fix/v3.1.1-writer
Nov 19, 2026
Merged

bjfultn merged 4 commits into
mainfrom
fix/v3.1.1-writer

Conversation

@bjfultn

@bjfultn bjfultn commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Fix for GHSA-4qp2-3768-j99g, plus the other defects reported privately against v3.1.0. Developed in the advisory's private fork, where Actions does not run; the CI job was reproduced by hand: the same install, ruff and pytest steps in python:3.9–3.12-bookworm containers on linux/amd64 (gcc 12). All pass (340 passed, 2 skipped; 339/3 on 3.9, where one existing test needs 3.10), with no compiler warnings under -Wall -Wextra. Also tested on macOS, Python 3.11.

Changes

TAP/writerecsmodule.c (rewritten)

  • Item 1, the advisory: names, units, descriptions and string values are held in memory sized to them; every formatted write is bounded; data dictionary formats are checked before being used as printf formats. Error paths close the file and free memory.
  • Item 2: integers are written at full 64-bit width (exactly, via Python, when larger). IPAC integer formats keep their flags.
  • Item 3: VOTable datatype="long" for longlong (and bigint), "int" for integer.
  • Item 4: CSV quotes doubled (RFC 4180); header names quoted when needed.
  • Also: VOTable FIELD attributes XML-escaped, ]]> split inside CDATA, control characters XML forbids replaced with U+FFFD; JSON keys and all control characters escaped.

TAP/writeresult.py: results whose row count is an exact multiple of the fetch size (10,000) were left unclosed (no </VOTABLE>, no JSON ]). Now closed by a final tail-only writer call; JSON row separators are written before each row so that call leaves valid JSON.

TAP/tapquery.py (item 5): the spatial index level is passed to ADQL as an int, so command-line CONTAINS queries work.

TAP/tap.py (item 6): UWS job documents are read through _parse_uws(), which silences bs4's XMLParsedAsHTMLWarning (logged on every job request). The HTML builder is kept, so tag look-ups are unchanged.

Testing

  • tests/writerecs_cases.py + tests/fixtures/writerecs_golden/: output for ordinary values captured from the v3.1.0 module; the rewrite reproduces all 25 files byte for byte, plus v3.1.0's IPAC width-overflow messages.
  • tests/test_writerecs.py, tests/test_v311_fixes.py: one or more tests per item; each fails on v3.1.0 and passes here. Long-input tests run in a child process so an overrun fails the test instead of crashing pytest.
  • Full suite: 340 passed, 2 skipped; ruff clean. Writer tests also run clean under AddressSanitizer.

Before release

  • Build and run the test matrix on Linux (done in Docker; see above)
  • Bump version to 3.1.1 (setup.py, TAP/tap.py debug line, Sphinx/conf.py)
  • Merge, tag and release 3.1.1, then publish the advisory

Items 7–10 (ADQL and SpatialIndex packages) are not addressed here.

🤖 Generated with Claude Code

bjfultn and others added 4 commits October 27, 2026 10:41
writerecsmodule.c is rewritten with the same output for ordinary values
(pinned by golden files captured from v3.1.0):

- Hold column names, units, descriptions and string values in memory
  sized to them, and bound every formatted write; check data dictionary
  formats before use.
- Write integers at full 64-bit width (exactly, when larger), keeping
  the flags of IPAC integer formats.
- VOTable: datatype "long" for longlong and "int" for integer; escape
  FIELD attributes; split "]]>" inside CDATA; replace control
  characters XML does not allow.
- CSV: double quotes inside values (RFC 4180).
- JSON: escape keys and all control characters.

Also:

- writeresult.py: close the document when the row count is a multiple
  of the fetch size (VOTable lacked </VOTABLE>, JSON lacked ']').
- tapquery.py: pass the spatial index level to ADQL as an int, so
  command-line CONTAINS queries work.
- tap.py: silence bs4's XMLParsedAsHTMLWarning when reading UWS job
  documents, which logged on every job request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Outside IPAC, the format kept from the '.' on was copied out of the full
format through a second buffer; gcc 12 -Wformat-truncation flagged the
copy. Build it from the parsed precision instead. Output is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bjfultn
bjfultn merged commit a1e6880 into main Nov 19, 2026
6 checks passed
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