-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
🐛 bug: Improve suffix range normalization #3902
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
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughA bug fix modifies HTTP suffix-range parsing in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
Summary of ChangesHello @gaby, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a bug in the handling of HTTP range requests, specifically for suffix ranges. The core change ensures that when a requested suffix is larger than the actual content, the calculated start of the range correctly defaults to the beginning of the content (index 0), preventing invalid range calculations. This fix is accompanied by a significant expansion of the test suite, providing robust validation for various suffix range scenarios and their expected HTTP status codes and Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly fixes a bug in suffix range normalization by ensuring the start of the range is never negative. The fix is simple and effective. The accompanying new test, Test_Ctx_Range_SuffixNormalization, provides good coverage for various suffix range scenarios, including oversized suffixes, which directly validates the fix. I've added one suggestion to improve the maintainability of the new test code by replacing magic numbers with a constant.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3902 +/- ##
==========================================
+ Coverage 91.65% 91.67% +0.01%
==========================================
Files 119 119
Lines 10039 10039
==========================================
+ Hits 9201 9203 +2
+ Misses 532 531 -1
+ Partials 306 305 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR improves the handling of HTTP suffix-byte-range requests by clamping negative start values to zero when the requested suffix length exceeds the resource size. This ensures compliance with RFC 7233, which specifies that suffix ranges larger than the resource should return the entire resource rather than causing errors.
- Changed suffix range calculation from
start = size - endtostart = max(size-end, 0)to prevent negative start values - Added comprehensive test coverage for suffix range normalization including edge cases (suffix smaller than, equal to, and larger than resource size)
- Validated proper HTTP status codes (206 for partial content, 200 for full content) and Content-Range headers
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| req.go | Improved suffix range normalization by clamping oversized suffix range starts using max() to prevent negative values |
| ctx_test.go | Added comprehensive test coverage for suffix range normalization scenarios including status codes and Content-Range header validation |
There was a problem hiding this 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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
ctx_test.go(1 hunks)req.go(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go
📄 CodeRabbit inference engine (AGENTS.md)
Prefer
github.com/gofiber/utils/v2helpers (for example,utils.Trim) when performing common operations such as string manipulation, whenever it is practical and appropriate for the surrounding code
Files:
req.goctx_test.go
**/*_test.go
📄 CodeRabbit inference engine (AGENTS.md)
When adding Go tests, always invoke
t.Parallel()at the start of each test and subtest to maximize concurrency
Files:
ctx_test.go
🧠 Learnings (2)
📓 Common learnings
Learnt from: gaby
Repo: gofiber/fiber PR: 3170
File: ctx_test.go:1721-1724
Timestamp: 2024-10-16T12:12:30.506Z
Learning: In the Go unit tests in `ctx_test.go`, it is acceptable to use invalid CIDR notation such as `"0.0.0.1/31junk"` for testing purposes.
📚 Learning: 2025-11-26T13:34:08.088Z
Learnt from: CR
Repo: gofiber/fiber PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-26T13:34:08.088Z
Learning: Applies to **/*_test.go : When adding Go tests, always invoke `t.Parallel()` at the start of each test and subtest to maximize concurrency
Applied to files:
ctx_test.go
🧬 Code graph analysis (1)
ctx_test.go (3)
ctx_interface_gen.go (1)
Ctx(18-432)constants.go (5)
HeaderRange(236-236)StatusRequestedRangeNotSatisfiable(89-89)HeaderContentRange(234-234)StatusPartialContent(58-58)StatusOK(52-52)req.go (1)
Range(19-22)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: Agent
- GitHub Check: repeated
- GitHub Check: unit (1.25.x, macos-latest)
- GitHub Check: unit (1.25.x, windows-latest)
- GitHub Check: lint
- GitHub Check: Compare
- GitHub Check: Analyse
🔇 Additional comments (1)
req.go (1)
741-821: Suffix-range clamping looks correct and aligns with HTTP semanticsUsing
start = max(size-end, 0)forbytes=-Navoids negative starts whenN >= sizeand cleanly normalizes oversized suffixes to the full range[0, size-1], while still relying on the existing guards (start > end || start < 0) and overflow checks inparseBound. This is consistent with the new tests and with howSendFilealready behaves for suffix ranges.
Summary