Raise UnsupportedFormat for a malformed DBF stream - #674
Open
eeshsaxena wants to merge 2 commits into
Open
Conversation
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'.
for more information, see https://pre-commit.ci
Author
|
Hi! Gentle nudge on this one whenever you have some bandwidth. It's a small, self-contained fix ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Loading a malformed or truncated DBF file surfaces low-level errors straight out of
Dataset().load(..., format='dbf')rather than tablib's ownUnsupportedFormat. Depending on how the bytes are broken you get astruct.error,IndexError,UnicodeDecodeError,KeyError, etc. from the vendored dbfpy parser.DBFFormat.detectalready wraps the parser intry/except Exception: return False, so tablib already treats any DBF parsing error as "not a valid DBF". I madeimport_setconsistent: it wraps the parse and raisesUnsupportedFormaton 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.