message: Fix problems related to `TF_OUT_OF_RANGE`
diff: @@ -121,6 +121,9 @@ static int64_t LoadBufferFromGCS(const std::string& path, size_t offset,
  int64_t read;
  if (!absl::SimpleAtoi(stream.headers().find("content-length")->second,
  &read)) {
  + // When we read a file with offset that is bigger than the actual file size.
  + // GCS will return an empty header (e.g no `content-length` header). In this
  + // case, we will set read to `0` and continue.
  if (TF_GetCode(status) == TF_OUT_OF_RANGE) {
  read = 0;
  } else {
  @@ -128,6 +131,8 @@ static int64_t LoadBufferFromGCS(const std::string& path, size_t offset,
  return -1;
  }
  }
  + // `TF_OUT_OF_RANGE` isn't considered as an error. So we clear it here.
  + TF_SetStatus(status, TF_OK, "");
  stream.read(buffer, read);
  read = stream.gcount();
  if (read < buffer_size) {
  @@ -216,6 +221,7 @@ int64_t Read(const TF_RandomAccessFile* file, uint64_t offset, size_t n,
  (std::min)(n - copy_size, gcs_file->buffer.size());
  memcpy(buffer + copy_size, gcs_file->buffer.data(), remaining_copy);
  copy_size += remaining_copy;
  + }
  if (copy_size < n) {
  // Forget the end-of-file flag to allow for clients that poll on the
  // same file.
  @@ -223,7 +229,6 @@ int64_t Read(const TF_RandomAccessFile* file, uint64_t offset, size_t n,
  TF_SetStatus(status, TF_OUT_OF_RANGE, "Read less bytes than requested");
  return copy_size;
  }
  - }
  TF_SetStatus(status, TF_OK, "");
  return copy_size;
  }
  