| 296 | } |
| 297 | |
| 298 | Result<int64_t> ValidateReadRange(int64_t offset, int64_t size, int64_t file_size) { |
| 299 | if (offset < 0 || size < 0) { |
| 300 | return Status::Invalid("Invalid read (offset = ", offset, ", size = ", size, ")"); |
| 301 | } |
| 302 | if (offset > file_size) { |
| 303 | return Status::IOError("Read out of bounds (offset = ", offset, ", size = ", size, |
| 304 | ") in file of size ", file_size); |
| 305 | } |
| 306 | return std::min(size, file_size - offset); |
| 307 | } |
| 308 | |
| 309 | Status ValidateWriteRange(int64_t offset, int64_t size, int64_t file_size) { |
| 310 | if (offset < 0 || size < 0) { |