Datagrunt 5.6.1: Zero-Pickle PDF Worker IPC, DuckDB Hardening & Bounded Rust CSV Scanning

November 25, 2026by Martin Graham

Datagrunt 5.6.1 is now available! This patch release delivers a defense-in-depth security and stability hardening sweep (PR #525) spanning PDF worker subprocess IPC, DuckDB session isolation, Rust CSV streaming memory bounds, dependency updates, source hygiene, and GitHub Actions automation.


Highlights in Datagrunt 5.6.1

  1. Zero-Pickle JSON PDF Worker IPC — Replaces pickle across PDF worker page and error replies with strict, schema-validated ASCII JSON (_page_ipc), explicit exception allowlisting, source-path verification, and parent-side password re-binding so PDF passwords never cross worker stdout.
  2. Hardened DuckDB Sessions & Spatial-Free Excel Export — Centralizes private in-memory DuckDB sessions with verified temp_directory='' and autoinstall_known_extensions=false, adds strict integer validation on sample_csv_query(limit), and switches CSVWriter(..., engine="duckdb").write_excel() to local Polars/XlsxWriter output without downloading DuckDB’s spatial extension.
  3. 16 MiB Per-Record Cap in Rust Streaming CSV Scans — Bounds per-record buffering (MAX_RECORD_READ_BYTES) in row_count_with_header and check_ragged so crafted unclosed-quote or newline-free inputs fail closed instead of growing unboundedly on the heap.
  4. Dependency, FIPS & Bidi Source Hygiene — Bumps the [pdf] extra dependency floor from Pillow>=12.2.0 to Pillow>=13.0.0, marks non-security hashlib.sha1 calls with usedforsecurity=False, and eliminates literal Unicode bidi control characters in favor of \u escape sequences.
  5. CI/CD & Automation Hardening — Eliminates shell=True in antigravity_workflow.py with strict git-ref validation, pins CI build/release tools (maturin==1.14.1, twine==7.0.0, bumpver==2026.1132), scopes SITE_TOKEN credentials in auto-publish-site.yml, and expands pip-audit to .[pdf,rationalize].

1. Zero-Pickle JSON PDF Worker IPC & Password Isolation

Previously, PDF extraction workers communicated extracted Page objects and exceptions back to the parent process using pickle. In Datagrunt 5.6.1, all worker IPC uses strict, bounded ASCII JSON — pickle is completely removed from worker communication:

  • Strict page and lazy-loader JSON codec (_page_ipc): Worker Page replies are encoded via the strict datagrunt.pdf.codec schema alongside validated JSON descriptors for the three allowlisted lazy loader types (PageDraw, PageRender, and FigureRead). On receipt, the parent verifies that every loader’s source path matches expected_source, rejecting unexpected loader redirection, and re-binds the PDF password locally in the parent process—meaning passwords never cross worker stdout.
  • Allowlisted JSON error replies: _process.error_reply() and _process.read_error() serialize exceptions as strict ASCII JSON (allow_nan=False, duplicate-key rejection, and NaN/Infinity rejection) against an explicit allowlist of classes in datagrunt.pdf.exceptions (DatagruntPDFError, PDFEncryptedError, PDFCorruptError, PDFSourceChangedError, BundleCorruptError) and standard builtins (OSError subclasses, ImportError/ModuleNotFoundError, ValueError, TypeError, IndexError, KeyError, RuntimeError, TimeoutError), preserving structured attributes (page_number, errno, strerror, filename, name). Any unlisted exception crosses safely as a DatagruntPDFError carrying "<type>: <message>".
  • Decoupled codec metadata: KINDS and ELEMENT_KINDS moved from frame.py into codec.py so worker IPC and JSON serialization never import polars or pyarrow.
  • Clear sandbox=True isolation scope: PDFReader and PDFWriter docstrings and reference docs now clarify that sandbox=True forces PDFium extraction, page rendering, and figure decoding into 2 GiB memory-capped python -I worker subprocesses for crash/OOM containment—it does not drop OS-level privileges (such as seccomp, Landlock, or Seatbelt).
from datagrunt import DatagruntPDFError, PDFReader, PDFWriter

# Isolate PDFium extraction, rendering, and figure decoding in 2 GiB python -I workers.
# Worker IPC exchanges strict JSON only; the password stays in the parent process.
try:
    reader = PDFReader("confidential.pdf", password="secret", sandbox=True)
    df = reader.to_dataframe()
    PDFWriter(reader.document).write_markdown("out/confidential.md")
except DatagruntPDFError as exc:
    print(f"PDF processing failed: {exc}")

2. Hardened Private DuckDB Sessions & Spatial-Free Excel Export

Every CSV, Excel, Parquet, and PDF reader/writer that opens a DuckDB connection now shares the same verified lockdown:

  • Verified no-spill, no-autoinstall connections: DuckDBQueries.connection, ExcelReaderEngine.query_data, and ParquetReaderEngine.query_data now open sessions via private_in_memory_connection(), which executes SET temp_directory='' and SET autoinstall_known_extensions=false, then queries current_setting(...) to confirm [("", False)] and fails closed with RuntimeError if not applied.
  • Strict SQL limit validation: DuckDBQueries.sample_csv_query(limit) validates that limit is a positive int (explicitly rejecting bool, strings, floats, None, and values < 1) with ValueError before SQL interpolation.
  • Spatial-free DuckDB Excel export: CSVWriter(..., engine="duckdb").write_excel() previously ran DuckDB’s INSTALL spatial; LOAD spatial; to write .xlsx files. In 5.6.1, it exports directly via self.queries.create_table(normalize_columns).pl().write_excel(filename), preserving DuckDB’s CSV parsing semantics and normalize_columns behavior while removing the network extension download entirely.
from datagrunt import CSVReader, CSVWriter, ExcelReader, ParquetReader

# All private DuckDB sessions disable temp-disk spilling and extension auto-install
with CSVReader("events.csv", engine="duckdb") as csv_reader:
    summary = csv_reader.query_data(
        f"SELECT count(*) AS total FROM {csv_reader.db_table}"
    ).pl()

# Exports .xlsx locally via Polars/XlsxWriter without downloading DuckDB's spatial extension
writer = CSVWriter("events.csv", engine="duckdb", normalize_columns=True)
writer.write_excel("events.xlsx")
writer.close()

# Excel and Parquet SQL queries share the same hardened private DuckDB session
with ExcelReader("workbook.xlsx") as xl_reader:
    print(xl_reader.query_data(f"SELECT * FROM {xl_reader.db_table} LIMIT 5").pl())

with ParquetReader("metrics.parquet") as pq_reader:
    print(pq_reader.query_data(f"SELECT * FROM {pq_reader.db_table} LIMIT 5").pl())

3. Bounded Per-Record Buffering in Rust CSV Streaming

In the native Rust core (rust/datagrunt-core/src/rows.rs and ragged.rs), csv_reader_streaming now wraps the decoded file stream in RecordBudgetReader and BoundedCsvReader with a 16 MiB (MAX_RECORD_READ_BYTES) per-record byte cap:

  • Unbounded file streaming for normal CSVs: The per-record byte counter resets before every CSV record, so multi-gigabyte CSV files with normal row widths continue to stream cleanly with constant memory.
  • Fail-closed protection against crafted inputs: Unclosed quoted fields or newline-free records exceeding 16 MiB abort early with io::ErrorKind::InvalidData rather than buffering the entire file in memory—raising OSError in row_count_with_header and returning False safely in check_ragged.
from datagrunt import CSVReader

reader = CSVReader("transactions.csv")
# Streams logical CSV records in Rust with a 16 MiB per-record memory cap
print("Logical rows (with header):", reader.row_count_with_header)

4. Dependency, Source Hygiene & CI/CD Hardening

Datagrunt 5.6.1 also lands targeted packaging, hygiene, and release-automation fixes:

  • Updated [pdf] dependency floor: pyproject.toml bumps the optional pdf dependency floor from Pillow>=12.2.0 to Pillow>=13.0.0.
  • FIPS & Unicode bidi source hygiene:
    • DuckDBQueries._set_database_table_name() passes usedforsecurity=False to hashlib.sha1(...) for its non-cryptographic DuckDB table-name suffix (tbl_<stem>_<hash>), preserving identical table names in FIPS-enabled Python environments.
    • datagrunt/rationalization/providers/base.py replaces literal Unicode bidirectional control characters in _DETAIL_BLANKS with explicit \u202a-\u202e\u2066-\u2069 escape sequences, removing raw bidi controls from source files while keeping bounded_detail() sanitization identical.
  • Workflow & release-script hardening:
    • scripts/antigravity_workflow.py replaces shell=True subprocess execution with shell=False argv sequences, adds validate_git_ref() (rejecting leading dashes, .., whitespace, control characters, and refs over 256 characters), and enforces a 30-second git command timeout.
    • .github/workflows/auto-publish-site.yml sets persist-credentials: false on the datagrunt-site checkout and passes SITE_TOKEN via scoped GIT_CONFIG_* environment headers only during the commit/push and deploy-verification steps.
    • .github/workflows/bump-version.yml pins bumpver==2026.1132, passes VERSION_PART through an environment variable, and validates it against patch|minor|major.
    • .github/workflows/build.yml pins maturin==1.14.1 and twine==7.0.0, and .github/workflows/ci.yml runs pip-audit against .[pdf,rationalize].

Upgrading to Datagrunt 5.6.1

Upgrade with uv:

uv pip install --upgrade "datagrunt[pdf,rationalize]"

Or with pip:

pip install --upgrade "datagrunt[pdf,rationalize]"

For full details on worker isolation, DuckDB session settings, and Rust CSV streaming, see the PDF Parsing Guide, Querying with DuckDB, and CSV Engines & Rust Acceleration.