eschutho opened a new pull request, #45380:
URL: https://github.com/apache/superset/pull/45380

   ### SUMMARY
   Corrupt ZIP uploads to the import endpoints return an opaque 500 instead of 
a 422.
   
   ### PROBLEM
   Each import endpoint checks `is_zipfile(upload)` and then calls 
`ZipFile(upload)`. `is_zipfile()` only validates the end-of-central-directory 
record, so a ZIP with a corrupt/truncated central directory passes it, and 
`ZipFile()` (or a later `bundle.read()`) raises a raw `zipfile.BadZipFile`. 
Nothing on these routes handles it, so it reaches the catch-all `Exception` 
handler and returns 500 (and logs an ERROR). Sibling code 
(`columnar_reader.py`, `reports/notifications/email.py`) already catches it.
   
   ### FIX
   Add an `open_import_bundle()` context manager in 
`commands/importers/v1/utils.py` that converts `BadZipFile` (on open or while 
reading) into the existing `IncorrectFormatError` (422), and use it at the 7 
API import sites (charts, dashboards, databases, datasets, importexport, saved 
queries, themes). Same bug class as #42366 / #42401 (raw library exception -> 
proper Superset exception); additive catch only.
   
   ### TESTING INSTRUCTIONS
   `pytest tests/unit_tests/commands/importers/v1/utils_test.py 
tests/unit_tests/importexport/api_test.py 
tests/unit_tests/databases/api_test.py`. The new tests fail on pre-fix code 
(ImportError / `500 == 422`) and pass after. Manual: POST a zip whose 
`PK\x01\x02` central-directory signature is overwritten to 
`/api/v1/assets/import/` -> 422.
   
   Three existing database tests mocked `superset.databases.api.ZipFile`; they 
now mock `open_import_bundle`.
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to