Skip to content

Commit bf34cd0

Browse files
hannahhowardlidel
andauthored
fix(gw): entity-bytes with negative indexes beyond file size (#523)
* 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]>
1 parent 3d57bce commit bf34cd0

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

.github/workflows/gateway-conformance.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ jobs:
1616
steps:
1717
# 1. Download the gateway-conformance fixtures
1818
- name: Download gateway-conformance fixtures
19-
uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@v0.4
19+
uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@v0.5
2020
with:
2121
output: fixtures
2222
merged: true
2323

2424
# 2. Build the car-gateway
2525
- name: Setup Go
26-
uses: actions/setup-go@v3
26+
uses: actions/setup-go@v4
2727
with:
2828
go-version: 1.21.x
2929
- name: Checkout boxo
30-
uses: actions/checkout@v3
30+
uses: actions/checkout@v4
3131
with:
3232
path: boxo
3333
- name: Build car-gateway
@@ -40,7 +40,7 @@ jobs:
4040

4141
# 4. Run the gateway-conformance tests
4242
- name: Run gateway-conformance tests
43-
uses: ipfs/gateway-conformance/.github/actions/test@v0.4
43+
uses: ipfs/gateway-conformance/.github/actions/test@v0.5
4444
with:
4545
gateway-url: http://127.0.0.1:8040
4646
json: output.json

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ The following emojis are used to highlight certain changes:
2424

2525
### Removed
2626

27-
- 🛠 `gateway`: the header configuration `Config.Headers` and `AddAccessControlHeaders` has been replaced by the new middleware provided by `NewHeaders`.
27+
### Fixed
28+
29+
- 🛠 `boxo/gateway`: when making a trustless CAR request with the "entity-bytes" parameter, using a negative index greater than the underlying entity length could trigger reading more data than intended
30+
- 🛠 `boxo/gateway`: the header configuration `Config.Headers` and `AddAccessControlHeaders` has been replaced by the new middleware provided by `NewHeaders`.
2831

2932
### Security
3033

gateway/blocks_backend.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ func walkGatewaySimpleSelector(ctx context.Context, p path.ImmutablePath, params
508508
return err
509509
}
510510
from = fileLength + entityRange.From
511+
if from < 0 {
512+
from = 0
513+
}
511514
foundFileLength = true
512515
}
513516

@@ -521,13 +524,15 @@ func walkGatewaySimpleSelector(ctx context.Context, p path.ImmutablePath, params
521524
}
522525

523526
to := *entityRange.To
524-
if (*entityRange.To) < 0 && !foundFileLength {
525-
fileLength, err = f.Seek(0, io.SeekEnd)
526-
if err != nil {
527-
return err
527+
if (*entityRange.To) < 0 {
528+
if !foundFileLength {
529+
fileLength, err = f.Seek(0, io.SeekEnd)
530+
if err != nil {
531+
return err
532+
}
533+
foundFileLength = true
528534
}
529535
to = fileLength + *entityRange.To
530-
foundFileLength = true
531536
}
532537

533538
numToRead := 1 + to - from

0 commit comments

Comments
 (0)