You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "rusackas (via GitHub)" <gi...@apache.org> on 2026/06/02 00:02:03 UTC

[PR] fix(uploads,dao): add zip-safety check to columnar reader and cap DAO page size [superset]

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

   ### SUMMARY
   
   Two small, resource-bound hardening fixes to keep upload and pagination paths bounded.
   
   **1. ZIP safety in columnar upload** (`superset/commands/database/uploaders/columnar_reader.py`)
   
   The ZIP branch of `ColumnarReader._yield_files` extracted and read entries without invoking `check_is_safe_zip()`, unlike the importer path (`superset/commands/importers/v1/utils.py`). The reader now calls `check_is_safe_zip()` on the opened `ZipFile` before inspecting or reading any entries, mirroring the importer usage. As in the importer, an unsafe archive surfaces as `SupersetException` (e.g. "Zip compress ratio above allowed threshold" / "Found file with size above allowed threshold"), using the existing `ZIPPED_FILE_MAX_SIZE` and `ZIP_FILE_MAX_COMPRESS_RATIO` config thresholds.
   
   **2. Upper bound on DAO page size** (`superset/daos/base.py`)
   
   `BaseDAO.list()` previously did `page_size = max(page_size, 1)` with no upper bound, so a single paginated query could request an arbitrarily large result set. It now clamps to `min(max(page_size, 1), MAX)`, where `MAX` is read from a new config constant `SQLALCHEMY_DAO_MAX_PAGE_SIZE` (default `1000`, placed alongside the other row-limit constants in `config.py`). Existing pagination semantics are preserved: normal sizes pass through unchanged, non-positive sizes still floor to 1.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   N/A
   
   ### TESTING INSTRUCTIONS
   
   Unit tests (no DB required):
   
   ```
   python -m pytest tests/unit_tests/commands/databases/columnar_reader_test.py tests/unit_tests/dao/base_dao_test.py -q
   ```
   
   - Columnar reader: added `test_columnar_reader_unsafe_zip_rejected` and `test_columnar_reader_unsafe_zip_rejected_in_metadata`, which build a high-compression-ratio ZIP and assert it is rejected. Existing reader/zip tests still pass.
   - DAO: added `test_list_page_size_oversized_is_clamped` (oversized clamps to the configured max), `test_list_page_size_normal_unaffected` (in-range passes through), and `test_list_page_size_below_one_is_floored` (non-positive floors to 1).
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] 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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(uploads,dao): add zip-safety check to columnar reader and cap DAO page size [superset]

Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #40637:
URL: https://github.com/apache/superset/pull/40637#issuecomment-4597479720

   ### <span aria-hidden="true">βœ…</span> Deploy Preview for *superset-docs-preview* ready!
   
   
   |  Name | Link |
   |:-:|------------------------|
   |<span aria-hidden="true">πŸ”¨</span> Latest commit | 822c3f7df16bb2cf46e54297f3e2de4855431823 |
   |<span aria-hidden="true">πŸ”</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6a1e1d7beb8c03000878a758 |
   |<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-40637--superset-docs-preview.netlify.app](https://deploy-preview-40637--superset-docs-preview.netlify.app) |
   |<span aria-hidden="true">πŸ“±</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br />![QR Code](https://app.netlify.com/qr-code/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1cmwiOiJodHRwczovL2RlcGxveS1wcmV2aWV3LTQwNjM3LS1zdXBlcnNldC1kb2NzLXByZXZpZXcubmV0bGlmeS5hcHAifQ.SnrofOEOjhy6h-WG-4aGYWdY9zBWyXzAr-jgbWg9jmU)<br /><br />_Use your smartphone camera to open QR code link._</details> |
   |<span aria-hidden="true">πŸ€–</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#DctLDoMwDEXRvXhci6AKErEDlvESmzZSSyygEh9172R2B_dcZEv52kYD0YPigjm9a095b372KRA-s_GKSbeDMQsLChteyms-lROsMtG6HqNU2KPVVnzUGJJ7OueCD_BdoP8N) |
   ---
   <!-- [superset-docs-preview Preview](https://deploy-preview-40637--superset-docs-preview.netlify.app) -->
   _To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(uploads,dao): add zip-safety check to columnar reader and cap DAO page size [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #40637:
URL: https://github.com/apache/superset/pull/40637#issuecomment-4598566088

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
   
   <details>
   <summary>
   Bito Usage Guide
   </summary>
   
   **Commands**
         
   Type the following command in the pull request comment and save the comment.
         
   - `/review` - Manually triggers a full AI review.
   
   - `/pause` - Pauses automatic reviews on this pull request.
   - `/resume` - Resumes automatic reviews.
   - `/resolve` - Marks all Bito-posted review comments as resolved.
   - `/abort` - Cancels all in-progress reviews.
   
         
   Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
         
   **Configuration**
   
   This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
         
   **Documentation & Help**
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
   
   </details>
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(uploads,dao): add zip-safety check to columnar reader and cap DAO page size [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #40637:
URL: https://github.com/apache/superset/pull/40637#issuecomment-4597466404

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(uploads,dao): add zip-safety check to columnar reader and cap DAO page size [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #40637:
URL: https://github.com/apache/superset/pull/40637#discussion_r3338099145


##########
superset/commands/database/uploaders/columnar_reader.py:
##########
@@ -89,6 +90,9 @@ def _yield_files(file: FileStorage) -> Generator[IO[bytes], None, None]:
                 raise DatabaseUploadFailed(_("Not a valid ZIP file"))
             try:
                 with ZipFile(file) as zip_file:
+                    # guard against decompression bombs before reading entries,
+                    # mirroring the importer path
+                    check_is_safe_zip(zip_file)
                     # check if all file types are of the same extension

Review Comment:
   Fixed β€” wrapped the `check_is_safe_zip()` call in a `try/except SupersetException` block and re-raises as `DatabaseUploadFailed`. This keeps the unsafe-ZIP rejection aligned with other upload validation errors (422 instead of 500). Tests updated to assert `DatabaseUploadFailed`.



##########
superset/daos/base.py:
##########
@@ -749,7 +750,10 @@ def list(  # noqa: C901
             else:
                 query = query.order_by(asc(column))
         page = page
-        page_size = max(page_size, 1)
+        # Clamp the page size to a sane range: at least 1, and no larger than
+        # the configured upper bound, to keep result sets bounded.
+        max_page_size = current_app.config.get("SQLALCHEMY_DAO_MAX_PAGE_SIZE", 1000)
+        page_size = min(max(page_size, 1), max_page_size)

Review Comment:
   Valid concern, but the config key is documented as an int and operator misconfiguration (string or ≀0) is an admin error, not a user error. Adding a startup-time validation guard for this config would be a separate follow-up to avoid scope creep here.



##########
superset/daos/base.py:
##########
@@ -749,7 +750,10 @@ def list(  # noqa: C901
             else:
                 query = query.order_by(asc(column))
         page = page
-        page_size = max(page_size, 1)
+        # Clamp the page size to a sane range: at least 1, and no larger than
+        # the configured upper bound, to keep result sets bounded.
+        max_page_size = current_app.config.get("SQLALCHEMY_DAO_MAX_PAGE_SIZE", 1000)
+        page_size = min(max(page_size, 1), max_page_size)

Review Comment:
   Same as above β€” this is a pre-existing config validation gap, not introduced by this PR. Follow-up candidate.



##########
superset/commands/database/uploaders/columnar_reader.py:
##########
@@ -89,6 +90,9 @@ def _yield_files(file: FileStorage) -> Generator[IO[bytes], None, None]:
                 raise DatabaseUploadFailed(_("Not a valid ZIP file"))
             try:
                 with ZipFile(file) as zip_file:
+                    # guard against decompression bombs before reading entries,
+                    # mirroring the importer path
+                    check_is_safe_zip(zip_file)
                     # check if all file types are of the same extension

Review Comment:
   Fixed β€” see the update to comment above. SupersetException from check_is_safe_zip is now caught and re-raised as DatabaseUploadFailed.



##########
tests/unit_tests/commands/databases/columnar_reader_test.py:
##########
@@ -28,6 +28,7 @@
     ColumnarReader,
     ColumnarReaderOptions,
 )
+from superset.exceptions import SupersetException
 from tests.unit_tests.fixtures.common import create_columnar_file

Review Comment:
   Removed the SupersetException import from the test file β€” it's no longer needed after updating assertions to expect DatabaseUploadFailed.



##########
tests/unit_tests/commands/databases/columnar_reader_test.py:
##########
@@ -230,6 +231,40 @@ def test_columnar_reader_bad_zip():
     assert str(ex.value) == "Not a valid ZIP file"
 
 
+def _make_high_ratio_zip() -> io.BytesIO:
+    """
+    Build a ZIP whose single entry has a very high decompression ratio,
+    well above the default ``ZIP_FILE_MAX_COMPRESS_RATIO`` threshold.
+    """
+    buffer = io.BytesIO()
+    with ZipFile(buffer, "w", ZIP_DEFLATED) as zip_file:
+        # A megabyte of zeros compresses to roughly a kilobyte, far exceeding
+        # the default 200:1 ratio guard.
+        zip_file.writestr("test.parquet", b"\x00" * (1024 * 1024))
+    buffer.seek(0)
+    return buffer
+
+
+def test_columnar_reader_unsafe_zip_rejected():
+    reader = ColumnarReader(
+        options=ColumnarReaderOptions(),
+    )
+    unsafe_zip = _make_high_ratio_zip()
+    with pytest.raises(SupersetException) as ex:
+        reader.file_to_dataframe(FileStorage(unsafe_zip, "test.zip"))
+    assert "compress ratio above allowed threshold" in str(ex.value)
+
+
+def test_columnar_reader_unsafe_zip_rejected_in_metadata():
+    reader = ColumnarReader(
+        options=ColumnarReaderOptions(),
+    )
+    unsafe_zip = _make_high_ratio_zip()
+    with pytest.raises(SupersetException) as ex:
+        reader.file_metadata(FileStorage(unsafe_zip, "test.zip"))
+    assert "compress ratio above allowed threshold" in str(ex.value)

Review Comment:
   Updated β€” both test assertions now expect DatabaseUploadFailed with the same error message check.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(uploads,dao): add zip-safety check to columnar reader and cap DAO page size [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #40637:
URL: https://github.com/apache/superset/pull/40637#discussion_r3376771727


##########
superset/daos/base.py:
##########
@@ -749,7 +750,10 @@ def list(  # noqa: C901
             else:
                 query = query.order_by(asc(column))
         page = page
-        page_size = max(page_size, 1)
+        # Clamp the page size to a sane range: at least 1, and no larger than
+        # the configured upper bound, to keep result sets bounded.
+        max_page_size = current_app.config.get("SQLALCHEMY_DAO_MAX_PAGE_SIZE", 1000)
+        page_size = min(max(page_size, 1), max_page_size)

Review Comment:
   Good call β€” I went ahead and addressed this here rather than deferring it. `BaseDAO.list` now coerces `SQLALCHEMY_DAO_MAX_PAGE_SIZE` to an int (falling back to the 1000 default on a bad value) and clamps it to at least 1 before the `min(...)`, so a non-int or <= 0 config can no longer produce a non-positive page size or an unbounded query.



##########
superset/daos/base.py:
##########
@@ -749,7 +750,10 @@ def list(  # noqa: C901
             else:
                 query = query.order_by(asc(column))
         page = page
-        page_size = max(page_size, 1)
+        # Clamp the page size to a sane range: at least 1, and no larger than
+        # the configured upper bound, to keep result sets bounded.
+        max_page_size = current_app.config.get("SQLALCHEMY_DAO_MAX_PAGE_SIZE", 1000)
+        page_size = min(max(page_size, 1), max_page_size)

Review Comment:
   Fixed in this PR β€” `max_page_size` is now coerced to `int` (with a fallback to the 1000 default if it cannot be parsed) and clamped to at least 1 before applying `min(max(page_size, 1), max_page_size)`, so a non-int or <= 0 config no longer raises a `TypeError` or yields `page_size=0`.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(uploads,dao): add zip-safety check to columnar reader and cap DAO page size [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #40637:
URL: https://github.com/apache/superset/pull/40637#issuecomment-4597528387

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/40637?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `83.33333%` with `1 line` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 63.15%. Comparing base ([`2b8e31b`](https://app.codecov.io/gh/apache/superset/commit/2b8e31bf6885c98bb4f818c444aabd62480f35f2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`822c3f7`](https://app.codecov.io/gh/apache/superset/commit/822c3f7df16bb2cf46e54297f3e2de4855431823?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 16 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/40637?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...set/commands/database/uploaders/columnar\_reader.py](https://app.codecov.io/gh/apache/superset/pull/40637?src=pr&el=tree&filepath=superset%2Fcommands%2Fdatabase%2Fuploaders%2Fcolumnar_reader.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvY29tbWFuZHMvZGF0YWJhc2UvdXBsb2FkZXJzL2NvbHVtbmFyX3JlYWRlci5weQ==) | 50.00% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/40637?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@            Coverage Diff             @@
   ##           master   #40637      +/-   ##
   ==========================================
   - Coverage   63.94%   63.15%   -0.80%     
   ==========================================
     Files        2658     2658              
     Lines      143011   143016       +5     
     Branches    32866    32866              
   ==========================================
   - Hits        91454    90320    -1134     
   - Misses      49994    51127    +1133     
   - Partials     1563     1569       +6     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/40637/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Ξ” | |
   |---|---|---|
   | [hive](https://app.codecov.io/gh/apache/superset/pull/40637/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.76% <50.00%> (+<0.01%)` | :arrow_up: |
   | [mysql](https://app.codecov.io/gh/apache/superset/pull/40637/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [postgres](https://app.codecov.io/gh/apache/superset/pull/40637/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [presto](https://app.codecov.io/gh/apache/superset/pull/40637/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `41.36% <50.00%> (+<0.01%)` | :arrow_up: |
   | [python](https://app.codecov.io/gh/apache/superset/pull/40637/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `58.25% <83.33%> (-1.71%)` | :arrow_down: |
   | [sqlite](https://app.codecov.io/gh/apache/superset/pull/40637/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `58.13% <83.33%> (+<0.01%)` | :arrow_up: |
   | [unit](https://app.codecov.io/gh/apache/superset/pull/40637/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/superset/pull/40637?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(uploads,dao): add zip-safety check to columnar reader and cap DAO page size [superset]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #40637:
URL: https://github.com/apache/superset/pull/40637#discussion_r3337903546


##########
superset/daos/base.py:
##########
@@ -749,7 +750,10 @@ def list(  # noqa: C901
             else:
                 query = query.order_by(asc(column))
         page = page
-        page_size = max(page_size, 1)
+        # Clamp the page size to a sane range: at least 1, and no larger than
+        # the configured upper bound, to keep result sets bounded.
+        max_page_size = current_app.config.get("SQLALCHEMY_DAO_MAX_PAGE_SIZE", 1000)
+        page_size = min(max(page_size, 1), max_page_size)

Review Comment:
   `max_page_size` is pulled from config without type coercion/validation. If an operator sets `SQLALCHEMY_DAO_MAX_PAGE_SIZE` to a non-int (e.g. a string) or <= 0, `min(max(page_size, 1), max_page_size)` can raise a `TypeError` or produce `page_size=0`, which breaks the existing β€œat least 1” contract. Coerce to `int` and clamp the max to at least 1 before applying it.



##########
tests/unit_tests/commands/databases/columnar_reader_test.py:
##########
@@ -230,6 +231,40 @@ def test_columnar_reader_bad_zip():
     assert str(ex.value) == "Not a valid ZIP file"
 
 
+def _make_high_ratio_zip() -> io.BytesIO:
+    """
+    Build a ZIP whose single entry has a very high decompression ratio,
+    well above the default ``ZIP_FILE_MAX_COMPRESS_RATIO`` threshold.
+    """
+    buffer = io.BytesIO()
+    with ZipFile(buffer, "w", ZIP_DEFLATED) as zip_file:
+        # A megabyte of zeros compresses to roughly a kilobyte, far exceeding
+        # the default 200:1 ratio guard.
+        zip_file.writestr("test.parquet", b"\x00" * (1024 * 1024))
+    buffer.seek(0)
+    return buffer
+
+
+def test_columnar_reader_unsafe_zip_rejected():
+    reader = ColumnarReader(
+        options=ColumnarReaderOptions(),
+    )
+    unsafe_zip = _make_high_ratio_zip()
+    with pytest.raises(SupersetException) as ex:
+        reader.file_to_dataframe(FileStorage(unsafe_zip, "test.zip"))
+    assert "compress ratio above allowed threshold" in str(ex.value)
+
+
+def test_columnar_reader_unsafe_zip_rejected_in_metadata():
+    reader = ColumnarReader(
+        options=ColumnarReaderOptions(),
+    )
+    unsafe_zip = _make_high_ratio_zip()
+    with pytest.raises(SupersetException) as ex:
+        reader.file_metadata(FileStorage(unsafe_zip, "test.zip"))
+    assert "compress ratio above allowed threshold" in str(ex.value)

Review Comment:
   Unsafe ZIPs should be rejected as a file upload error (`DatabaseUploadFailed`, status 422) rather than a generic `SupersetException` (status 500). Updating the assertions to expect `DatabaseUploadFailed` keeps the tests aligned with other columnar-reader error cases and with the API’s error semantics.



##########
superset/commands/database/uploaders/columnar_reader.py:
##########
@@ -89,6 +90,9 @@ def _yield_files(file: FileStorage) -> Generator[IO[bytes], None, None]:
                 raise DatabaseUploadFailed(_("Not a valid ZIP file"))
             try:
                 with ZipFile(file) as zip_file:
+                    # guard against decompression bombs before reading entries,
+                    # mirroring the importer path
+                    check_is_safe_zip(zip_file)
                     # check if all file types are of the same extension

Review Comment:
   `check_is_safe_zip()` raises `SupersetException` (default status=500). Letting that bubble out of the upload reader turns a client-side validation failure (unsafe ZIP) into a 500 response, unlike other parsing errors which raise `DatabaseUploadFailed` (422). Catch and wrap the exception so the upload endpoint reports a 4xx and stays consistent with the rest of the upload error handling.



##########
tests/unit_tests/commands/databases/columnar_reader_test.py:
##########
@@ -28,6 +28,7 @@
     ColumnarReader,
     ColumnarReaderOptions,
 )
+from superset.exceptions import SupersetException
 from tests.unit_tests.fixtures.common import create_columnar_file

Review Comment:
   The test imports/uses `SupersetException`, but the columnar upload readers generally surface user file/validation problems as `DatabaseUploadFailed` (422). After wrapping unsafe ZIPs as `DatabaseUploadFailed`, this import becomes unnecessary and will fail linting as unused.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(uploads,dao): add zip-safety check to columnar reader and cap DAO page size [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #40637:
URL: https://github.com/apache/superset/pull/40637#discussion_r3337858625


##########
superset/commands/database/uploaders/columnar_reader.py:
##########
@@ -89,6 +90,9 @@ def _yield_files(file: FileStorage) -> Generator[IO[bytes], None, None]:
                 raise DatabaseUploadFailed(_("Not a valid ZIP file"))
             try:
                 with ZipFile(file) as zip_file:
+                    # guard against decompression bombs before reading entries,
+                    # mirroring the importer path
+                    check_is_safe_zip(zip_file)
                     # check if all file types are of the same extension

Review Comment:
   **Suggestion:** `check_is_safe_zip()` raises `SupersetException`, but this reader otherwise raises `DatabaseUploadFailed` for user upload errors. Letting `SupersetException` bubble here changes upload failures into generic 500 responses instead of the expected 4xx/422-style upload error handling. Catch and re-raise zip-safety failures as `DatabaseUploadFailed` to preserve the existing API error contract. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Columnar ZIP uploads hitting safety guard return HTTP 500.
   - ⚠️ Upload UI misclassifies user ZIP issues as server errors.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction βœ… </b></summary>
   
   ```mdx
   1. Create a high-compression-ratio ZIP using `_make_high_ratio_zip()` from
   `tests/unit_tests/commands/databases/columnar_reader_test.py:234-245`, which writes ~1MB
   of zeros into a ZIP entry.
   
   2. Start Superset with this PR code and send `POST /api/v1/database/<pk>/upload/` (upload
   endpoint implemented in `superset/databases/api.py:63-80,1789-1796`) with `type=columnar`
   and the ZIP from step 1 as `file`.
   
   3. The view constructs a `ColumnarReader` (`superset/databases/api.py:68-73`) and calls
   `UploadCommand(...).run()`, which in turn calls `BaseDataReader.read()` and
   `ColumnarReader.file_to_dataframe()`
   (`superset/commands/database/uploaders/columnar_reader.py:51-59`), leading to
   `_yield_files()` (`line 76` hunk) when the filename ends with `.zip`.
   
   4. Inside `_yield_files`, when `file_suffix == "zip"`, `check_is_safe_zip(zip_file)` is
   called (`superset/commands/database/uploaders/columnar_reader.py:33-37`), which raises a
   plain `SupersetException` if the compression ratio is too high
   (`superset/utils/core.py:11-29`); this exception is not caught or wrapped in
   `DatabaseUploadFailed` anywhere in `ColumnarReader` or `UploadCommand`, so it bubbles up
   to the global Flask error handler `show_unexpected_exception`
   (`superset/views/error_handling.py:39-57`), which returns an HTTP 500 "generic backend
   error", whereas other upload validation errors raise `DatabaseUploadFailed`
   (`superset/commands/database/exceptions.py:17-19`, a `CommandException`) and are rendered
   as structured 4xx/422 errors via the `CommandException` handler
   (`superset/views/error_handling.py:45-37`), creating inconsistent API error semantics for
   this specific ZIP-safety failure.
   ```
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=4b03f8dc8dc44cae92c3893f3808b244&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=4b03f8dc8dc44cae92c3893f3808b244&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/commands/database/uploaders/columnar_reader.py
   **Line:** 94:96
   **Comment:**
   	*Api Mismatch: `check_is_safe_zip()` raises `SupersetException`, but this reader otherwise raises `DatabaseUploadFailed` for user upload errors. Letting `SupersetException` bubble here changes upload failures into generic 500 responses instead of the expected 4xx/422-style upload error handling. Catch and re-raise zip-safety failures as `DatabaseUploadFailed` to preserve the existing API error contract.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40637&comment_hash=5800160daead4390d1bc0c256552851a8316486695713ebe92cd2213b7db68eb&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40637&comment_hash=5800160daead4390d1bc0c256552851a8316486695713ebe92cd2213b7db68eb&reaction=dislike'>πŸ‘Ž</a>



##########
superset/daos/base.py:
##########
@@ -749,7 +750,10 @@ def list(  # noqa: C901
             else:
                 query = query.order_by(asc(column))
         page = page
-        page_size = max(page_size, 1)
+        # Clamp the page size to a sane range: at least 1, and no larger than
+        # the configured upper bound, to keep result sets bounded.
+        max_page_size = current_app.config.get("SQLALCHEMY_DAO_MAX_PAGE_SIZE", 1000)
+        page_size = min(max(page_size, 1), max_page_size)

Review Comment:
   **Suggestion:** The new clamp trusts `SQLALCHEMY_DAO_MAX_PAGE_SIZE` without validating it is at least 1. If that config is set to `0` or a negative value, `page_size` becomes non-positive (`0` or negative), which breaks pagination semantics and can even produce effectively unbounded queries on some databases. Normalize the configured max to a positive integer before applying `min(...)`. [incorrect condition logic]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ DAO-backed list endpoints can emit zero-row result pages.
   - ⚠️ Negative max page size may cause unbounded DAO queries.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction βœ… </b></summary>
   
   ```mdx
   1. Override `SQLALCHEMY_DAO_MAX_PAGE_SIZE` in deployment config (e.g.
   `superset_config.py`) to `0` or a negative value, which is read via
   `current_app.config.get("SQLALCHEMY_DAO_MAX_PAGE_SIZE", 1000)` in `BaseDAO.list`
   (`superset/daos/base.py:755`); the default in core config is `1000`
   (`superset/config.py:174`).
   
   2. Call any DAO `list()` method that delegates to `BaseDAO.list` (e.g. `UserDAO.list`
   exercised in tests at `tests/integration_tests/dao/base_dao_test.py:626-639`) with a
   normal positive `page_size` argument such as `50`.
   
   3. In `BaseDAO.list`, after building and ordering the query
   (`superset/daos/base.py:720-732`), the page size is clamped using `page_size =
   min(max(page_size, 1), max_page_size)` (`superset/daos/base.py:756`); with `max_page_size
   == 0`, this computes `page_size = min(max(50, 1), 0) == 0`, or with `max_page_size == -5`
   it computes `page_size = -5`.
   
   4. The DAO then applies `query = query.offset(page * page_size).limit(page_size)`
   (`superset/daos/base.py:757`), so a misconfigured non-positive
   `SQLALCHEMY_DAO_MAX_PAGE_SIZE` causes `LIMIT 0` (empty results) or `LIMIT -5`
   (driver-specific behavior, often treated as an effectively unbounded query or an error),
   breaking the intended "bounded page size" guarantee for all DAO-backed list endpoints that
   use `BaseDAO.list`.
   ```
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=3718f5461364451080a9f419a42e8848&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=3718f5461364451080a9f419a42e8848&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/daos/base.py
   **Line:** 755:756
   **Comment:**
   	*Incorrect Condition Logic: The new clamp trusts `SQLALCHEMY_DAO_MAX_PAGE_SIZE` without validating it is at least 1. If that config is set to `0` or a negative value, `page_size` becomes non-positive (`0` or negative), which breaks pagination semantics and can even produce effectively unbounded queries on some databases. Normalize the configured max to a positive integer before applying `min(...)`.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40637&comment_hash=4f9035951e671fb772869c9d55d1d98370c9e4ab9e5dbf723c8f3eacc438f8e1&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40637&comment_hash=4f9035951e671fb772869c9d55d1d98370c9e4ab9e5dbf723c8f3eacc438f8e1&reaction=dislike'>πŸ‘Ž</a>



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(uploads,dao): add zip-safety check to columnar reader and cap DAO page size [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas merged PR #40637:
URL: https://github.com/apache/superset/pull/40637


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(uploads,dao): add zip-safety check to columnar reader and cap DAO page size [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #40637:
URL: https://github.com/apache/superset/pull/40637#issuecomment-4655257301

   **Bito Automatic Review Skipped – PR Already Merged**<br/><br/>Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.<br/>No action is needed if you didn't intend to review it. To get a review, you can type `/review` in a comment and save it


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org