Skip to content

Commit

Permalink
Handle index overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammedabdon authored Nov 14, 2024
1 parent 498d39b commit 1cfd105
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/layout/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func ParseTileIndexWidth(index string) (uint64, uint64, error) {
if err != nil || n >= 1000 || len(indexPath) != 3 {
return 0, 0, fmt.Errorf("failed to parse tile index")
}
if c.N > (math.MaxUint64-n)/1000 {

Check failure on line 135 in api/layout/paths.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, ubuntu-latest)

undefined: c

Check failure on line 135 in api/layout/paths.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, ubuntu-latest)

undefined: math

Check failure on line 135 in api/layout/paths.go

View workflow job for this annotation

GitHub Actions / Run govulncheck

undefined: c

Check failure on line 135 in api/layout/paths.go

View workflow job for this annotation

GitHub Actions / Run govulncheck

undefined: math

Check failure on line 135 in api/layout/paths.go

View workflow job for this annotation

GitHub Actions / lint

undefined: c

Check failure on line 135 in api/layout/paths.go

View workflow job for this annotation

GitHub Actions / lint

undefined: math) (typecheck)

Check failure on line 135 in api/layout/paths.go

View workflow job for this annotation

GitHub Actions / lint

undefined: c

Check failure on line 135 in api/layout/paths.go

View workflow job for this annotation

GitHub Actions / lint

undefined: math) (typecheck)
return 0, 0, fmt.Errorf("failed to parse tile index")
}
i = i*1000 + n
}

Expand Down
5 changes: 5 additions & 0 deletions api/layout/paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ func TestParseTileLevelIndexWidth(t *testing.T) {
pathIndex: "x001/002.p/256",
wantErr: true,
},
{
pathLevel: "63",
pathIndex: "x999/x999/x999/x999/x999/x999/999.p/255",
wantErr: true,
},
} {
desc := fmt.Sprintf("pathLevel: %q, pathIndex: %q", test.pathLevel, test.pathIndex)
t.Run(desc, func(t *testing.T) {
Expand Down

0 comments on commit 1cfd105

Please sign in to comment.