Datagrunt 5.6.1: Zero-Pickle PDF Worker IPC, DuckDB Hardening & Bounded Rust CSV Scanning
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
- Zero-Pickle JSON PDF Worker IPC — Replaces
pickleacross 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. - Hardened DuckDB Sessions & Spatial-Free Excel Export — Centralizes private in-memory DuckDB sessions with verified
temp_directory=''andautoinstall_known_extensions=false, adds strict integer validation onsample_csv_query(limit), and switchesCSVWriter(..., engine="duckdb").write_excel()to local Polars/XlsxWriter output without downloading DuckDB’sspatialextension. - 16 MiB Per-Record Cap in Rust Streaming CSV Scans — Bounds per-record buffering (
MAX_RECORD_READ_BYTES) inrow_count_with_headerandcheck_raggedso crafted unclosed-quote or newline-free inputs fail closed instead of growing unboundedly on the heap. - Dependency, FIPS & Bidi Source Hygiene — Bumps the
[pdf]extra dependency floor fromPillow>=12.2.0toPillow>=13.0.0, marks non-securityhashlib.sha1calls withusedforsecurity=False, and eliminates literal Unicode bidi control characters in favor of\uescape sequences. - CI/CD & Automation Hardening — Eliminates
shell=Trueinantigravity_workflow.pywith strict git-ref validation, pins CI build/release tools (maturin==1.14.1,twine==7.0.0,bumpver==2026.1132), scopesSITE_TOKENcredentials inauto-publish-site.yml, and expandspip-auditto.[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): WorkerPagereplies are encoded via the strictdatagrunt.pdf.codecschema alongside validated JSON descriptors for the three allowlisted lazy loader types (PageDraw,PageRender, andFigureRead). On receipt, the parent verifies that every loader’s source path matchesexpected_source, rejecting unexpected loader redirection, and re-binds the PDFpasswordlocally 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, andNaN/Infinityrejection) against an explicit allowlist of classes indatagrunt.pdf.exceptions(DatagruntPDFError,PDFEncryptedError,PDFCorruptError,PDFSourceChangedError,BundleCorruptError) and standardbuiltins(OSErrorsubclasses,ImportError/ModuleNotFoundError,ValueError,TypeError,IndexError,KeyError,RuntimeError,TimeoutError), preserving structured attributes (page_number,errno,strerror,filename,name). Any unlisted exception crosses safely as aDatagruntPDFErrorcarrying"<type>: <message>". - Decoupled codec metadata:
KINDSandELEMENT_KINDSmoved fromframe.pyintocodec.pyso worker IPC and JSON serialization never importpolarsorpyarrow. - Clear
sandbox=Trueisolation scope:PDFReaderandPDFWriterdocstrings and reference docs now clarify thatsandbox=Trueforces PDFium extraction, page rendering, and figure decoding into 2 GiB memory-cappedpython -Iworker 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, andParquetReaderEngine.query_datanow open sessions viaprivate_in_memory_connection(), which executesSET temp_directory=''andSET autoinstall_known_extensions=false, then queriescurrent_setting(...)to confirm[("", False)]and fails closed withRuntimeErrorif not applied. - Strict SQL limit validation:
DuckDBQueries.sample_csv_query(limit)validates thatlimitis a positiveint(explicitly rejectingbool, strings, floats,None, and values< 1) withValueErrorbefore SQL interpolation. - Spatial-free DuckDB Excel export:
CSVWriter(..., engine="duckdb").write_excel()previously ran DuckDB’sINSTALL spatial; LOAD spatial;to write.xlsxfiles. In 5.6.1, it exports directly viaself.queries.create_table(normalize_columns).pl().write_excel(filename), preserving DuckDB’s CSV parsing semantics andnormalize_columnsbehavior 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 MiBabort early withio::ErrorKind::InvalidDatarather than buffering the entire file in memory—raisingOSErrorinrow_count_with_headerand returningFalsesafely incheck_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.tomlbumps the optionalpdfdependency floor fromPillow>=12.2.0toPillow>=13.0.0. - FIPS & Unicode bidi source hygiene:
DuckDBQueries._set_database_table_name()passesusedforsecurity=Falsetohashlib.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.pyreplaces literal Unicode bidirectional control characters in_DETAIL_BLANKSwith explicit\u202a-\u202e\u2066-\u2069escape sequences, removing raw bidi controls from source files while keepingbounded_detail()sanitization identical.
- Workflow & release-script hardening:
scripts/antigravity_workflow.pyreplacesshell=Truesubprocess execution withshell=Falseargv sequences, addsvalidate_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.ymlsetspersist-credentials: falseon thedatagrunt-sitecheckout and passesSITE_TOKENvia scopedGIT_CONFIG_*environment headers only during the commit/push and deploy-verification steps..github/workflows/bump-version.ymlpinsbumpver==2026.1132, passesVERSION_PARTthrough an environment variable, and validates it againstpatch|minor|major..github/workflows/build.ymlpinsmaturin==1.14.1andtwine==7.0.0, and.github/workflows/ci.ymlrunspip-auditagainst.[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.