-
Notifications
You must be signed in to change notification settings - Fork 98
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
fix(gw): entity-bytes with negative indexes beyond file size #523
Conversation
Codecov ReportAttention:
@@ Coverage Diff @@
## main #523 +/- ##
==========================================
- Coverage 65.58% 65.00% -0.58%
==========================================
Files 207 204 -3
Lines 25589 25567 -22
==========================================
- Hits 16782 16620 -162
- Misses 7334 7461 +127
- Partials 1473 1486 +13
|
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.
Thank you, adding a guard here makes sense, but since this is HTTP Gateway, [initial instinct] I feel is we should error instead of silently fixing up – rationale below.
(we will engage on this in january, after holiday break, and will include a fix in Kubo 0.26, but posting today so we have more time to think about this)
As an implementer I don't want to have to make status code decisions after I've successfully processed the first block; I know boxo is fine buffering all of the blocks at the beginning but that's not what we do elsewhere and the transport is currently designed for maximal streaming. So introducing a requirement to status code at some point >1 block down into a DAG is going to introduce further incompatibilities between implementations. I think I see the negative start value landing before the start of the file in a similar way to the end value being beyond the end of the file, it's like setting the end to MaxInt64, or |
when using entity-bytes with a file and a negative start range, insure that ranges more negative than the file's length are bounded at zero
6718f0b
to
3242478
Compare
(looked deeper with a bit more fresh eyes today) I agree, truncation proposed here will be less headache across systems than HTTP-style error that is hard to enforce across implementations. (Given the non-HTTP abstractions we will be dealing with, and the fact we already have a situation where we return CAR With HTTP 200 on error cases such as sub-path not found in a DAG, it is not as big precedent as I originally thought, and truncation instead of error makes implementations easier) @hannahhoward agree, this is a niche thing, but I do think we should have one sentence in spec and basic tests for edge cases like this because someone may build things that depend on them, like @rvagg noted above in #523 (comment) Created ipfs/kubo#10320 to test this PR against ipfs/gateway-conformance#190. Will try to land it this week, next steps are:
|
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.
- switched to tests released in https://github.com/ipfs/gateway-conformance/releases/tag/v0.5.0
- kubo fix(gw): negative entity-bytes beyond file size kubo#10320 runs against both [email protected] and this PR, and CI is green there (ci in this PR might fail until that is merged upstream, so ok to disregard)
- DSL for deterministic CID assertions is out of scope here, will track it in Implement tooling to document hardcoded CIDs gateway-conformance#112
- Bubbling up, thanks all!
upstream fix ipfs/boxo#523 got merged
Cosmetic clarification based on discussion that happened in ipfs/boxo#523
* Bump ipfs/gateway-conformance from 0.4.1 to 0.5.0 * chore: ipfs/boxo#523 * refactor: NewNoopTracerProvider deprecation --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Marcin Rataj <[email protected]>
* fix(gateway): bound negative indexes to size of file * fix: adjust negative to when from is negative too * chore: [email protected] https://github.com/ipfs/gateway-conformance/releases/tag/v0.5.0 --------- Co-authored-by: Marcin Rataj <[email protected]>
Goal
Fix the following problem:
entity-bytes
parameter of a trustless HTTP request.entity-bytes=-1000,-50
on a 100 byte file-900
1 + 50 - -900
= 951Implementation
Very simple fix -- if after adding the entity length, the from is still negative, simply set it to 0.
This is the logic already implemented in the IPLD selector for ranges -- https://github.com/ipld/go-ipld-prime/blob/master/traversal/selector/matcher.go#L49
For discussion
This wil cause a gateway conformance test to fail, which is due to a failure in the way the test is setup -- the issue is documented here: ipfs/gateway-conformance#189