Skip to content

fix: honor MaxBatchURLs and handle unannounced batch response lengths - #2296

Open
0xrlawrence wants to merge 1 commit into
yetanotherco:stagingfrom
0xrlawrence:fix/operator-batch-download-limits
Open

fix: honor MaxBatchURLs and handle unannounced batch response lengths#2296
0xrlawrence wants to merge 1 commit into
yetanotherco:stagingfrom
0xrlawrence:fix/operator-batch-download-limits

Conversation

@0xrlawrence

Copy link
Copy Markdown

Description

Two independent correctness problems in the operator's batch download path, plus a small guard.

parseBatchURLs returns one more URL than MaxBatchURLs. The loop appends and then checks len(urls) > MaxBatchURLs, so it breaks only after the sixth entry is already in the slice. With MaxBatchURLs = 5, an input carrying seven URLs returns six. Verified against the current implementation:

input "u1,u2,u3,u4,u5,u6,u7"   before: 6 URLs   after: 5 URLs

Moving the bound check to the top of the loop fixes it, and a table test now pins the limit.

Servers that do not announce a length are always rejected. resp.ContentLength is -1 for chunked transfer encoding. That value passes the > MaxBatchSize check, then makes the io.LimitedReader budget -1 + 1 = 0 bytes, so reader.N <= 0 fires and the batch is refused as oversized. The read now falls back to MaxBatchSize when no length is announced, which keeps it bounded either way.

maxRetries < 1 would nil-deref. A non-positive retry count skips the request loop entirely, leaving resp nil for the resp.Body dereference below. Clamped to at least one attempt.

The first hunk also converts a stray space-indented comment to a tab so the file is gofmt-clean.

Type of change

  • Bug fix

Checklist

  • “Hotfix” to testnet, everything else to staging
  • Unit tests added

Verified with go vet ./operator/pkg/ and gofmt on staging. The package's own tests need the Rust FFI shared libraries to link, so the parseBatchURLs behaviour above was confirmed by running the old and new implementations side by side.

parseBatchURLs appended before checking the limit, so an input with more
than MaxBatchURLs entries returned MaxBatchURLs+1 URLs. Move the bound
check to the top of the loop and add a table test covering the limit.

getBatchFromDataService used resp.ContentLength directly as the read
bound. A server that does not announce a length (chunked transfer
encoding) reports -1, which made the LimitedReader budget 0 bytes and
caused every such response to be rejected as oversized. Fall back to the
configured MaxBatchSize in that case so the read stays bounded either way.

A maxRetries below 1 would also skip the request loop entirely and leave
resp nil for the deref that follows, so clamp it to at least one attempt.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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