Skip to content

Raise UnsupportedFormat for a malformed DBF stream - #674

Open
eeshsaxena wants to merge 2 commits into
jazzband:masterfrom
eeshsaxena:fix/dbf-import-unsupportedformat
Open

Raise UnsupportedFormat for a malformed DBF stream#674
eeshsaxena wants to merge 2 commits into
jazzband:masterfrom
eeshsaxena:fix/dbf-import-unsupportedformat

Conversation

@eeshsaxena

Copy link
Copy Markdown

Loading a malformed or truncated DBF file surfaces low-level errors straight out of Dataset().load(..., format='dbf') rather than tablib's own UnsupportedFormat. Depending on how the bytes are broken you get a struct.error, IndexError, UnicodeDecodeError, KeyError, etc. from the vendored dbfpy parser.

DBFFormat.detect already wraps the parser in try/except Exception: return False, so tablib already treats any DBF parsing error as "not a valid DBF". I made import_set consistent: it wraps the parse and raises UnsupportedFormat on any parser error. I also build the rows before touching the dataset so a failure part-way through doesn't leave a half-populated Dataset.

Added a test (truncated header + non-DBF bytes) that raises the raw IndexError on master and passes with the change; valid DBF import/export and the rest of the DBF tests are unchanged. Found it by fuzzing the format importers.

eeshsaxena and others added 2 commits August 14, 2026 23:59
Importing a malformed or truncated DBF let the vendored dbfpy parser raise a
variety of low-level errors (struct.error, IndexError, UnicodeDecodeError,
KeyError, ...) straight out of load(). Wrap the parse in import_set and raise
UnsupportedFormat instead, consistent with detect() which already treats any
DBF parsing error as 'not a valid DBF'.
@eeshsaxena

Copy link
Copy Markdown
Author

Hi! Gentle nudge on this one whenever you have some bandwidth. It's a small, self-contained fix (Raise UnsupportedFormat for a malformed DBF stream), and it's currently mergeable with no conflicts. No urgency at all, and I'm happy to make any changes you'd like. Thanks for maintaining tablib!

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