Skip to content

UNCOMPRESS() decompresses zlib payload into untracked memory before length validation, causing memory DoS #70198

Closed

Description

@Debra-He

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

UNCOMPRESS() accepts a binary string in this format:

payload[0:4] = declared uncompressed length, uint32 little-endian
payload[4:]  = zlib compressed stream

The input does not have to be generated by COMPRESS(), so an authenticated SQL user can manually construct a small zlib payload that expands to a very large result.
Example:

SET GLOBAL tidb_mem_quota_query = 1073741824;

SELECT @@tidb_mem_quota_query;
SELECT LENGTH(UNCOMPRESS(0x<4-byte-length-header + large-zlib-payload>));

In the reproduced case, the payload was about 1.16 MB but decompressed to 1,200,000,000 bytes.

2. What did you expect to see? (Required)

TiDB should limit and track memory usage during UNCOMPRESS().
If the decompressed output exceeds the declared length or query memory quota, the query should stop instead of continuing to allocate memory.

3. What did you see instead (Required)

TiDB fully decompresses the zlib stream into a bytes.Buffer first, and only checks the declared length after decompression finishes.
The decompression buffer is not tracked by the query memory tracker, so the query can exceed tidb_mem_quota_query.
Observed result:

tidb_mem_quota_query: 1073741824
UNCOMPRESS result length: 1200000000
query succeeded
tidb-server VmHWM increased from ~125 MB to ~2.6 GB

4. What is your TiDB version? (Required)

TiDB v8.5.6

Activity

  1. Debra-He commented on Jul 29, 2026

    @Debra-He
    ContributorAuthor

    /severity moderate

  2. kennedy8312 commented on Jul 29, 2026

    @kennedy8312

    /sig execution

  3. kennedy8312 commented on Jul 29, 2026

    @kennedy8312

    tidb-triage-bot AI rationale

    • sig/execution: The bug occurs during runtime evaluation of the UNCOMPRESS() SQL function and its untracked memory allocation.
  4. added a commit that references this issue on Jul 30, 2026
    c6e3cf8
  5. djshow832 commented on Aug 1, 2026

    @djshow832
    Contributor

    This is a security bug and blocks the v8.5.8 release, so I'm updating the severity to major.

  6. added a commit that references this issue on Aug 3, 2026
    2a3eafa
  7. added
    affects-8.1This bug affects the 8.1.x(LTS) versions.
    affects-7.5This bug affects the 7.5.x(LTS) versions.
    on Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-7.5This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.affects-8.5This bug affects the 8.5.x(LTS) versions.contributionThis PR is from a community contributor.fuzz/sqlancerseverity/majorsig/sql-infraSIG: SQL Infratype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions