Privacy and preparation
Dataset corruption detection checklist for truncated business exports
By SourceX Editorial · Updated
10 sections
Short answer
To detect a truncated export, make three independent counts agree: file sizes and SHA-256 digests recorded by the export job as it writes, a structural end-of-file check for each format, and record counts per month and stratum reconciled to reports run inside the source system. A checksum alone only proves the copy matches what was hashed, even if that was already cut short.
Checklist
Dataset corruption detection
Key takeaways
- A file that opens is not a complete file; truncated CSVs and capped spreadsheets open without complaint.
- Hash files inside the export job at write time, and verify without options that skip missing files.
- Every common format has a testable ending: the Parquet footer, the gzip trailer, zip entry CRCs and a strict CSV parse.
- Reconcile parsed record counts by month and stratum against source system reports run by a second person.
- Log every explained difference with a reason code and stop for a re-export when a gap has no known cause.
How do you detect a truncated business export before delivery?
Detect truncation by making three independent counts agree: the bytes (size and checksum recorded by the export job itself), the structure (every file ends where its format says it must), and the source (record counts per stratum match a report run inside the source system). A truncated export can pass any one of these on its own. It rarely passes all three.
Most suppliers check only that files open. That proves almost nothing: a CSV cut off at row 400,000 opens cleanly, and a spreadsheet saved at its row ceiling opens with no warning. The protocol on this page is built for the moment just before a business hands an offered dataset to a buyer, when a missing month or a half-written archive is still cheap to fix.
It complements, rather than repeats, the manifest and checksum guide for transfers, which proves that what arrived matches what was sent. Here the question comes earlier: whether what was sent was ever complete.
Why a matching checksum can still certify a broken export
A checksum proves a copy is identical to the file that was hashed, so if the file was hashed after it was cut short, verification passes every time. Integrity of transfer and completeness of export are different properties, and a manifest only covers the first.
Tooling can hide gaps too. The GNU coreutils checksum utilities accept an --ignore-missing option that, when verifying, does not fail or report status for missing files; it is meant for checking a subset of downloads, but in a release script it lets a missing archive part pass silently. Run verification without it, and compare the manifest's file list with the directory listing as a separate step.
The fix is ordering. Record the size and SHA-256 digest at the moment the export job finishes writing, inside the job, and record the source counts from the system's own reporting at the same cut-off. Python's hashlib, for example, always provides sha256 and offers a file_digest helper for hashing a file object. Hashing later, on a laptop, after a copy, certifies whatever the copy happened to contain.
Where do business exports get cut short?
Truncation usually comes from a limit nobody noticed, not from a disk failure. The table lists the patterns that show up most in exports from CRMs, help desks, ERPs and field service systems, and the check that catches each one.
| Failure pattern | How it happens | What it looks like | Check that catches it |
|---|---|---|---|
| Spreadsheet row ceiling | Data passed through Excel, whose worksheet holds 1,048,576 rows (65,536 in legacy .xls) | Row count exactly at the ceiling, latest records missing | Flag any file whose row count equals a known ceiling |
| Cell length ceiling | Long notes or email bodies saved through a spreadsheet, where a cell holds up to 32,767 characters | Text fields ending mid-sentence at the same length | Maximum field length per column against the source |
| Pagination stopped early | An API export loop ended on an error or rate limit and wrote what it had | Round-number counts, latest timestamp well before the cut-off | Source count reconciliation and max timestamp check |
| Job killed mid-write | Timeout, disk full or a closed session during the write | Last line partial; compressed file fails its trailer check | Structural end-of-file check per format |
| Missing archive part | Multi-part upload or split archive with one part never copied | Fewer parts than the manifest lists | File list compared to directory listing, no skip options |
| Broken quoting | Embedded line breaks or quotes in free text not quoted as RFC 4180 recommends | Row count from line count disagrees with parsed record count | Strict parse with record count, not line count |
| Window boundary error | Date filter used an exclusive end date or a different time zone | One day or one month short at the edge | Per-month counts against the source report |
| Orphaned children | Parent table exported in full, child table (attachments, comments) truncated | Tickets with no comments in recent months | Child-per-parent ratio by month |
Does each file end where its format says it should?
Every common export format has an ending you can test, and a truncated file almost never has a valid one. Check the end of the file before you spend time profiling its contents.
Parquet files end with the file metadata, a 4-byte metadata length and the 4-byte magic number PAR1, according to the Apache Parquet format specification; a file cut off mid-write lacks that footer, so a reader cannot locate its column chunks. Gzip members end with a trailer holding a CRC-32 and ISIZE, the length of the uncompressed input modulo 2 to the 32nd power, under RFC 1952. Python's gzip module raises BadGzipFile, and can also raise EOFError, on invalid gzip input, so decompressing the whole stream to the end is a real test, not a formality.
Zip archives can be tested entry by entry: Python's ZipFile.testzip reads every file in the archive, checks its CRC and headers, and returns the name of the first bad file. For CSV, parse with a strict dialect, which in Python's csv module raises an error on bad input, and count parsed records rather than lines. The csv documentation notes that line_num is not the same as the number of records returned, because records can span multiple lines, which is exactly why wc -l is the wrong count for exports with free-text fields.
Source count reconciliation: the check a file cannot pass by itself
Reconcile the export against counts produced inside the source system for the same filter and cut-off, broken down by month and by any stratum that matters to the buyer. A file can be structurally perfect and still hold eleven months of a twelve-month scope.
Good control totals come from the system's own reports or an admin query, run by someone other than the person who built the export. Record the report name, its filter and the time it ran. Compare record counts per month, distinct parent IDs, the minimum and maximum source timestamps, and for child tables the ratio of children to parents per month. A ratio that falls sharply in the most recent months is the signature of a child export that stopped early.
Expect small, explainable differences. Records can be deleted or merged between the report and the export, and preparation steps such as de-identification or scope filtering remove records on purpose. Log each difference with a reason code; an unexplained difference is the one that blocks release.
The file size, checksum and source count validation protocol
Run the protocol in order, because each step assumes the previous one passed. Record the evidence column for every release so a buyer's acceptance reviewer can repeat the checks without asking for anything new.
| Step | Check | Pass rule | Evidence to record |
|---|---|---|---|
| 1. Freeze scope | Write the systems, objects, filter and cut-off time | Scope statement signed off before export | Scope note with cut-off timestamp and time zone |
| 2. Take control totals | Run source reports for the same filter, by month and stratum | Reports run at the cut-off by a second person | Report names, filters, run times, counts |
| 3. Hash at write | Export job records size and SHA-256 per file on completion | Every file has a digest written by the job | Manifest with file name, bytes, digest, writer |
| 4. File list match | Compare manifest entries to the delivery directory | Same set of names, no extras, no skips | Diff output with zero differences |
| 5. Structural end check | Parquet footer, full gzip decompress, zip entry test, strict CSV parse | Every file reaches a valid end | Per-file pass result and tool version |
| 6. Ceiling scan | Row counts and field lengths against known limits | No file or field sits exactly at a ceiling | List of counts and maximum lengths |
| 7. Count reconciliation | Parsed records per month and stratum against control totals | Differences within the agreed tolerance and explained | Reconciliation sheet with reason codes |
| 8. Edge and child checks | Min and max timestamps; child-to-parent ratio by month | Edges match the scope; no late-period collapse | Edge dates and ratio table |
| 9. Exception log | Every difference, exclusion and known gap | No unexplained item remains | Signed exception log |
| 10. Release record | Protocol version, operator, date, result | All steps passed or exceptions accepted | One-page release record kept with the manifest |
Worked example (illustrative): a help desk export split across three archives
Illustrative only. A software company prepares two years of help desk tickets and comments for a licensing review. The export job writes tickets and comments as gzipped CSV, split across three archives, and records a digest for each file as it finishes.
Step 4 finds two archives in the delivery folder against three in the manifest; the third upload had failed silently. Re-copying it fixes the file list. Step 5 then fails on one comments file: decompression ends early because the export job was stopped by a session timeout. The job's wrapper had still hashed the partial file when the session ended, so the checksum matched, and only the structural check caught it.
After a re-export, step 7 shows ticket counts within 0.3 percent of the source reports for every month, explained by tickets merged after the report ran. Comments per ticket hold steady at roughly four for the first 20 months, then fall to under one in the last four, which step 8 flags as a late-period collapse. The comment export had used a page cap; a second run without it restores the ratio.
The exception: 41 tickets are missing in one month because the company's own retention rule deleted spam tickets after 90 days. That gap is real, explainable and stays in the exception log with the rule cited, rather than blocking the release.
Defects that change the buyer's decision even when every file opens
Some defects pass every structural check and still change what the dataset is worth for its declared task. They are worth a deliberate look because a buyer's acceptance sample is likely to find them.
- Text truncated at a fixed length, which removes the resolution or conclusion from the longest and often most useful records.
- A boundary month cut short, so the most recent period, the one a buyer cares about for drift, is underweighted.
- Outcome fields blank for recent records because cases were still open at the cut-off, which looks like missing labels.
- Timestamps rounded to midnight or converted to a single time zone, which breaks any sequence or duration task.
- Attachments referenced in records but absent from the package.
- Schema changes mid-history, such as a renamed status code, with no dictionary entry to map old to new values.
When a release should stop for a re-export instead of a patch
Stop and re-export when the cause of a gap is unknown, when a structural check fails on any file, or when more than one step needs an exception for the same period. Patching a broken export with a second partial export creates overlap and duplicate records that are harder to explain than the original gap.
Narrow the scope instead when one system or period cannot be reconciled at all, for example because the source reports no longer cover an archived year. Ask for specialist review when the shortfall might come from a privacy or retention rule, because removing records for legal reasons should be documented by the person who owns that rule, not inferred by the data team.
Bringing a reconciled export to a licensing assessment
For a business thinking of licensing selected records directly to SourceX, the opening step is a brief assessment of the company, made before any export is shared. A release record like the one above makes the questions about history and volume quick to answer; buyers generally want a consistent run of at least a couple of years and tens of thousands of records or more in one system, judged deal by deal.
Since SourceX does not host multi-terabyte sets, a very large export is read from the seller's own storage or shipped on encrypted drives, and the size, digest and count evidence produced at export travels with it either way.
Frequently asked questions
Is a checksum enough to prove an export is complete?
No. A checksum proves a copy matches the file that was hashed, so a file hashed after it was truncated verifies perfectly. Completeness needs a structural end-of-file check and a count reconciliation against the source system.
Why does the row count from wc -l differ from the record count?
Free-text fields can contain line breaks inside quoted values, so one record can span several lines. Count records with a CSV parser; Python's csv documentation notes that line_num differs from the number of records returned for exactly this reason.
How much difference from the source count is acceptable?
Agree a tolerance in advance and require every difference to have a reason code, such as merged, deleted after the report, or excluded during preparation. The size of the tolerance matters less than whether each difference is explained.
What does a truncated Parquet file look like?
A complete Parquet file ends with its metadata, a 4-byte length and the magic number PAR1. A truncated file lacks that footer, so readers fail to open it, which makes structural checking easy as long as you actually open every file.
Who should run the source count report?
Someone other than the person who built the export, using the source system's own reporting at the same cut-off and filter. A second person catches filter mistakes that the export author would repeat in both places.
Sources
- A Parquet file ends with the file metadata, a 4-byte little-endian metadata length and the 4-byte magic number PAR1. Source
- Each gzip member ends with a CRC-32 of the uncompressed data and ISIZE, the input length modulo 2^32. Source
- Python's gzip module raises BadGzipFile for invalid gzip files, and EOFError or zlib.error can also be raised. Source
- ZipFile.testzip reads all files in an archive, checks their CRCs and headers and returns the first bad file name. Source
- Python's csv module raises an error on bad input with a strict dialect, and line_num differs from the number of records because records can span lines. Source
- hashlib always includes sha256 and provides file_digest for hashing a file object. Source
- GNU coreutils checksum verification with --ignore-missing does not fail or report status for missing files. Source
- RFC 4180 says fields containing line breaks, double quotes and commas should be enclosed in double quotes. Source
- Excel worksheets hold 1,048,576 rows by 16,384 columns, and a cell can contain 32,767 characters. Source
See if your company qualifies
A short company assessment. No data uploads are needed.