Skip to content

Fix/streaming uncompress dict #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 25, 2025
Merged

Conversation

kjdev
Copy link
Owner

@kjdev kjdev commented May 25, 2025

Summary by CodeRabbit

  • New Features

    • Added a new test to verify streaming compression and decompression with dictionaries using the zstd PHP extension.
  • Bug Fixes

    • Improved support for streaming decompression with dictionaries, including better handling of unknown frame content sizes and enhanced error management.

Copy link

coderabbitai bot commented May 25, 2025

"""

Walkthrough

A new test file was added to verify streaming compression and decompression with dictionaries using the zstd PHP extension. Additionally, the zstd_uncompress_dict function was refactored to support streaming decompression when the frame content size is unknown, improving error handling and output buffer management.

Changes

File(s) Change Summary
tests/dictionary_02.phpt Added a new test for streaming compression and decompression with dictionaries using the zstd extension.
zstd.c Refactored zstd_uncompress_dict to support streaming decompression for unknown frame sizes, improved error handling, and adjusted output buffer management.

Sequence Diagram(s)

sequenceDiagram
    participant TestScript
    participant ZstdExtension
    participant Libzstd

    TestScript->>ZstdExtension: Compress data with dictionary (streaming)
    ZstdExtension->>Libzstd: Compress using provided dictionary
    Libzstd-->>ZstdExtension: Compressed data
    ZstdExtension-->>TestScript: Write compressed data to file

    TestScript->>ZstdExtension: Decompress data with dictionary (streaming)
    ZstdExtension->>Libzstd: Decompress (handle unknown frame size)
    Libzstd-->>ZstdExtension: Decompressed data (streaming)
    ZstdExtension-->>TestScript: Return decompressed data
Loading

Poem

In the warren where data flows free,
A new test hops in, as bright as can be.
Dictionaries in streams, now handled with care,
Decompressing unknowns—no need to despair!
With buffers that grow and errors that warn,
This rabbit’s code leaps, robust and reborn.
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 79afa04 and 8ed8865.

📒 Files selected for processing (1)
  • tests/dictionary_02.phpt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/dictionary_02.phpt
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: ci (8.3-zts, php)
  • GitHub Check: ci (8.3-zts, apcu, php)
  • GitHub Check: ci (8.1, x86, ts, vs16, true, apcu)
  • GitHub Check: ci (8.4, x64, ts, vs17, false)
  • GitHub Check: ci (8.1, x64, ts, vs16, true, apcu)
  • GitHub Check: ci (8.3, x86, nts, vs16, true)
  • GitHub Check: ci (8.1, x64, nts, vs16, true)
  • GitHub Check: ci (8.4, x86, ts, vs17, false)
  • GitHub Check: ci (8.1, x64, nts, vs16, false, apcu)
  • GitHub Check: ci (8.1, x64, nts, vs16, true, apcu)
  • GitHub Check: ci (8.3, x86, ts, vs16, false)
  • GitHub Check: ci (8.3, x86, ts, vs16, true)
  • GitHub Check: ci (8.3, x86, nts, vs16, false, apcu)
  • GitHub Check: ci (8.3, x64, nts, vs16, true, apcu)
  • GitHub Check: ci (8.4, x86, nts, vs17, true)
  • GitHub Check: ci (8.3, x64, ts, vs16, true)
  • GitHub Check: ci (8.4, x86, ts, vs17, true)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kjdev
Copy link
Owner Author

kjdev commented May 25, 2025

@coderabbitai review

Copy link

coderabbitai bot commented May 25, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
zstd.c (1)

582-596: Consider preventing potential double-free issues.

While the current code flow is correct, it would be safer to set output = NULL after efree(output) to prevent any potential double-free issues if the code is modified in the future.

Apply this diff to improve safety:

 if (ZSTD_IS_ERROR(result)) {
     zend_string_efree(output);
+    output = NULL;
     ZSTD_WARNING("%s", ZSTD_getErrorName(result));
     RETVAL_FALSE;
 } else if (result != size) {
     zend_string_efree(output);
+    output = NULL;
     ZSTD_WARNING("failed to uncompress");
     RETVAL_FALSE;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 044cc55 and 79afa04.

📒 Files selected for processing (2)
  • tests/dictionary_02.phpt (1 hunks)
  • zstd.c (1 hunks)
🔇 Additional comments (5)
zstd.c (4)

546-550: LGTM! Well-structured variable declarations.

The new variables are appropriately typed and necessary for implementing streaming decompression support.


557-566: Good implementation of frame content size handling.

The three-way logic correctly handles all possible scenarios:

  • Empty frames (size == 0)
  • Invalid frames (ZSTD_CONTENTSIZE_ERROR)
  • Streaming frames (ZSTD_CONTENTSIZE_UNKNOWN)

The initial buffer size estimation for streaming mode is reasonable.


568-578: Excellent error handling and resource management.

The code properly creates the decompression context and dictionary with appropriate error messages and cleanup on failure.


597-636: Excellent streaming decompression implementation.

The streaming mode correctly:

  • Initializes input/output buffers
  • References the dictionary using the streaming API
  • Handles dynamic buffer expansion
  • Includes comprehensive error handling with proper resource cleanup
  • Breaks the loop when decompression is complete (result == 0)
tests/dictionary_02.phpt (1)

9-10:

✅ Verification successful

Verify that required test data files exist.

The test depends on data.inc and data.dic files. Please ensure these files are present in the test directory.

Run the following script to verify the test data files:


🏁 Script executed:

#!/bin/bash
# Description: Verify that required test data files exist for the dictionary test.

# Test: Check if data.inc exists
fd -t f "data.inc" tests/

# Test: Check if data.dic exists
fd -t f "data.dic" tests/

# Test: List all dictionary-related test files to understand the test structure
fd -t f "dictionary" tests/

Length of output: 181


Required test data files verified

Both tests/data.inc and tests/data.dic are present in the tests/ directory, satisfying the test’s dependencies. No further action needed.

@kjdev kjdev force-pushed the fix/streaming-uncompress-dict branch from 8db8932 to 8ed8865 Compare May 25, 2025 22:33
@kjdev
Copy link
Owner Author

kjdev commented May 25, 2025

@coderabbitai review

Copy link

coderabbitai bot commented May 25, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kjdev kjdev merged commit 8ed8865 into master May 25, 2025
95 checks passed
@kjdev kjdev deleted the fix/streaming-uncompress-dict branch May 25, 2025 22:50
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