Repository navigation
Check the offset of the range an Azure endpoint returns against the requested one - #120955
Conversation
…equested one A successful `Download` is not enough to trust the body: an endpoint, or a proxy in front of it, that ignores the requested range answers `200 OK` with the whole object from byte 0, and the reader consumed that body as if it started at the requested offset - both on the sequential path (after a seek or on a reopen) and in `readBigAt`. The caller then got the wrong bytes under the right offsets, which is silent data corruption. The start of the returned range (`Content-Range`, which the SDK reports as 0 for a `200 OK` response) is now checked against the requested offset before the body is read, and a mismatch is `HTTP_RANGE_NOT_SATISFIABLE`. A full-object response is accepted exactly when the request started at 0, where it is a correct answer, the same as in `ReadWriteBufferFromHTTP`. `src/Disks/tests/gtest_azure_read_buffer_range_check.cpp` drives a positioned read and a sequential read after a seek against a fake endpoint that ignores ranges, and a read at offset 0 and a well-behaved endpoint as controls. This is one of the independent parts of #115706, which was reverted in #120419.
|
Workflow [PR], commit [ec702c4] Summary: ❌
AI ReviewSummaryThis PR adds a left-bound range check to Azure blob downloads and new gtests around endpoints that ignore byte ranges. It catches the wrong-start cases the new helper checks, but the sequential reader still does not satisfy its advertised exact right-bound contract, so the patch is not complete yet. Findings❌ Blockers
Final Verdict
LLVM Coverage ReportMeasured on commit ec702c4.
Changed lines: Changed C/C++ lines covered: 85/87 (97.70%) · Uncovered code |
| /// would hand the caller the wrong bytes under the right offsets - silent data corruption - so | ||
| /// the start of the returned range is checked against the requested one before the body is read. | ||
| /// The SDK reports a `200 OK` response as the range starting at 0, so a full-object response is | ||
| /// accepted exactly when the request started at 0, where it is a correct answer, the same as in |
There was a problem hiding this comment.
supportsRightBoundedReads() promises that setReadUntilPosition will stop exactly at the requested bound, but this helper now also accepts a full-object 200 OK whenever the request starts at 0. That is still wrong for bounded reads: initialize stores total_size = data_stream->Length() + offset, and nextImpl then uses that full length directly, so setReadUntilPosition(16) can expose bytes past 16 before the next call notices and throws LOGICAL_ERROR. Please either reject whole-object responses when a shorter right bound is active, or clamp the visible stream length to the requested bound, and add a regression test for offset == 0 with read_until_position < blob_size.
The `ignore_range` mode of the fake endpoint - answering every request with `200 OK` and the blob from byte 0, the way a proxy that does not understand ranges does - and the `HTTP_RANGE_NOT_SATISFIABLE` and `LOGICAL_ERROR` error codes are left over from #115706, where the check of the range an endpoint returns lived in the same change as the premature end. No test here uses them. That check is #120955, and it brings its own range-ignoring endpoint in `src/Disks/tests/gtest_azure_read_buffer_range_check.cpp`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…reopen range check The AI review asked that a reopened download be rejected when it does not start at the current offset, and that the data a response hands out be capped at `read_until_position`. The first half is `checkReturnedRange` from #120955, now on master and merged here; `AzureBoundedRead.RangeIgnoringEndpointIsRejectedOnReopen` pins that it applies to the reopen added by this PR. For the second half, `nextImpl` no longer reads past the right bound when a response runs longer than requested (e.g. a whole-object `200 OK` answering a ranged request at offset 0); before, the caller received the extra bytes and the next call threw `Attempt to read beyond right offset`. `AzureBoundedRead.LongerResponseIsCutAtTheRightBound` fails without the cap. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…nly the core bound fix The original PR #120910 builds on Azure reader changes that are not in 26.3 (#119054, #120955, #120963, `s3_validate_etag_on_read`, `LazyReadFromObjectStorageSource`, the `gtest_azure_read_buffer` fake transport). Resolved by taking the 26.3 tree for every touched path and porting only the fix itself to `ReadBufferFromAzureBlobStorage`: - the bound of the current download (`total_size`) is the locally set `read_until_position`, and the `Content-Length` of the response can only shorten it; - `setReadUntilPosition` discards the bytes buffered under the previous, wider bound and rewinds `offset`, so a tightened bound takes effect immediately. Not backported: `If-Match` pinning with `azure_validate_etag_on_read` and the `AZURE_OBJECT_CHANGED_DURING_READ` error code, the `std::optional` right bound, the `file_size` constructor argument, and the tests that depend on those (the gtest file does not exist in 26.3, `05259_lazy_materialization_azure_etag_pinned`, the integration test). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o 26.8 The cherry-pick of #120910 conflicted because 26.8 lacks the prerequisite Azure read fixes that landed on `master` first: #119054 (lazy blob client, `readBigAt` fix, and the creation of `gtest_azure_read_buffer.cpp`), #120955 (`checkReturnedRange`) and #120963 (reopen on a premature end of a bounded read). Resolution: - `ReadBufferFromAzureBlobStorage` is the 26.8 version with the changes of #120910 applied on top: `read_until_position` becomes `std::optional<size_t>`, the current download is bounded by `getTotalSizeOfCurrentDownload`, `setReadUntilPosition` drops the bytes buffered past a tighter bound, and every `Download` is pinned with `If-Match` to `expected_etag`, with the `ETag` of the response checked and `412` reported as `AZURE_OBJECT_CHANGED_DURING_READ`. The `file_size` argument is reported by `tryGetFileSize`. - `AzureObjectStorage::readObject` uses `connection_params.getContainer` as in 26.8. - `AZURE_OBJECT_CHANGED_DURING_READ` keeps the code 1021 from `master`; `END` is raised to it. - `azure_validate_etag_on_read` is declared in the 26.8 style, with its history entry in the `26.10` section of `SettingsChangesHistory.cpp`. - `gtest_azure_read_buffer.cpp` is added with the tests of #120910 only. The tests that belong to the prerequisites (`AzureReadBigAt.DoesNotTrustResponseLength`, `AzureReadBigAt.ReturnsAccumulatedCountOnTruncatedResponse`, `AzureReadUntilPosition.ShortRangeResponse`) are dropped, the `AzureObjectStorage` constructor takes the 26.8 `auth_method` argument, and `AzureReadBigAt.RejectsReplacedBlobThroughIfMatch` calls `getFileSize` first, because in 26.8 that is what creates the blob client for `readBigAt`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #115706
Related: #120419
A successful
Downloadis not enough to trust the body: an Azure Blob Storage endpoint, or a proxy in front of it, that ignores the requested range answers200 OKwith the whole object from byte 0, andReadBufferFromAzureBlobStorageconsumed that body as if it started at the requested offset. This happens on the sequential path (a read after a seek, or a download reopened after a retry) and inreadBigAtalike. The caller then received the wrong bytes under the right offsets: silent data corruption.The start of the returned range is now checked against the requested offset before the body is read, in both places, and a mismatch is reported as
HTTP_RANGE_NOT_SATISFIABLE. The SDK reports a200 OKresponse as a range starting at 0, so a full-object response is accepted exactly when the request started at 0, where it is a correct answer, the same wayReadWriteBufferFromHTTPtreats it.src/Disks/tests/gtest_azure_read_buffer_range_check.cppdrives a positioned read at offset 40 and a sequential read after a seek to 40 against a fake endpoint that ignores ranges, and asserts the error; a positioned read at offset 0 against the same endpoint, and a sequential read against a well-behaved one, are the controls.This is one of the independent parts of #115706, which was reverted in #120419.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reads from Azure Blob Storage now verify that the returned range starts at the requested offset, so an endpoint or proxy that ignores the
Rangeof a request fails the read withHTTP_RANGE_NOT_SATISFIABLEinstead of delivering the wrong bytes.Workflow [PR]
Sync PR [sync-upstream/pr/120955]
Version info
26.10.1.313-master(included in26.10and later)