diff --git a/google/resumable_media/_upload.py b/google/resumable_media/_upload.py
index bd4b197..dd5aaed 100644
--- a/google/resumable_media/_upload.py
+++ b/google/resumable_media/_upload.py
@@ -835,11 +835,12 @@ def get_next_chunk(stream, chunk_size, total_bytes):
         ValueError: If there is no data left to consume. This corresponds
             exactly to the case ``end_byte < start_byte``, which can only
             occur if ``end_byte == start_byte - 1``.
-        ValueError: If the stream has been read past ``total_bytes`` (this
-            is in the case that ``total_bytes`` is not :data:`None`).
     """
     start_byte = stream.tell()
-    payload = stream.read(chunk_size)
+    if total_bytes is not None and start_byte + chunk_size >= total_bytes > 0:
+        payload = stream.read(total_bytes - start_byte)
+    else:
+        payload = stream.read(chunk_size)
     end_byte = stream.tell() - 1
 
     num_bytes_read = len(payload)
@@ -861,10 +862,6 @@ def get_next_chunk(stream, chunk_size, total_bytes):
                 u"Stream is already exhausted. There is no content remaining."
             )
 
-        if end_byte >= total_bytes:
-            msg = _STREAM_READ_PAST_TEMPLATE.format(end_byte + 1, total_bytes)
-            raise ValueError(msg)
-
     content_range = get_content_range(start_byte, end_byte, total_bytes)
     return start_byte, payload, content_range
 

Blob.upload_from_file fails if 8MB < size-parameter < file-size 
#### Environment details

  - OS type and version: Linux Fedora 32 x86_64 
  - Python version: Python 3.8.2
  - pip version: pip 20.1
  - `google-cloud-storage` version: 1.28.1

#### Steps to reproduce

  1. create a file larger than 8MB, e.g. 16MB
  2. upload to GCS with Blob.upload_from_file() with size parameter set to 12 MB.

#### Code example

```python
with open("16MB-file.txt", "rb") as d:
    blob = Blob('upload-bug.txt', storage_client.get_bucket('some-bucket'))
    blob.upload_from_file(d, size=12_000_000)
```

#### Stack trace
```
  File "test-gcs-upload-bug.py", line 16, in <module>
    blob.upload_from_file(d, size=12_000_000)
  File "venv/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 1557, in upload_from_file
    created_json = self._do_upload(
  File "venv/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 1423, in _do_upload
    response = self._do_resumable_upload(
  File "venv/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 1331, in _do_resumable_upload
    response = upload.transmit_next_chunk(transport)
  File "venv/lib/python3.8/site-packages/google/resumable_media/requests/upload.py", line 418, in transmit_next_chunk
    method, url, payload, headers = self._prepare_request()
  File "venv/lib/python3.8/site-packages/google/resumable_media/_upload.py", line 550, in _prepare_request
    start_byte, payload, content_range = get_next_chunk(
  File "venv/lib/python3.8/site-packages/google/resumable_media/_upload.py", line 866, in get_next_chunk
    raise ValueError(msg)
ValueError: 16000000 bytes have been read from the stream, which exceeds the expected total 12000000.
```

diff --git a/tests/unit/test__upload.py b/tests/unit/test__upload.py
index 6f87401..278eab8 100644
--- a/tests/unit/test__upload.py
+++ b/tests/unit/test__upload.py
@@ -859,20 +859,22 @@ class Test_get_next_chunk(object):
         stream = io.BytesIO(b"not empty WAT!")
         with pytest.raises(ValueError) as exc_info:
             _upload.get_next_chunk(stream, 1, 0)
-
         exc_info.match(u"Stream specified as empty, but produced non-empty content.")
 
-    def test_read_past_known_size(self):
-        data = b"more content than we expected"
+    def test_success_known_size_lt_stream_size(self):
+        data = b"0123456789"
         stream = io.BytesIO(data)
-        chunk_size = len(data)
-        total_bytes = chunk_size - 3
+        chunk_size = 3
+        total_bytes = len(data) - 2
 
-        with pytest.raises(ValueError) as exc_info:
-            _upload.get_next_chunk(stream, chunk_size, total_bytes)
+        # Splits into 3 chunks: 012, 345, 67
+        result0 = _upload.get_next_chunk(stream, chunk_size, total_bytes)
+        result1 = _upload.get_next_chunk(stream, chunk_size, total_bytes)
+        result2 = _upload.get_next_chunk(stream, chunk_size, total_bytes)
 
-        exc_info.match(u"bytes have been read from the stream")
-        exc_info.match(u"exceeds the expected total")
+        assert result0 == (0, b"012", u"bytes 0-2/8")
+        assert result1 == (3, b"345", u"bytes 3-5/8")
+        assert result2 == (6, b"67", u"bytes 6-7/8")
 
     def test_success_known_size(self):
         data = b"0123456789"

pip install -e .[requests]
parse_log_pytest
requirements.txt
pytest pytest-cov mock flake8 black
apt-get update apt-get install -y gcc
3.7
docs_build/requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
black==23.3.0
certifi @ file:///croot/certifi_1671487769961/work/certifi
charset-normalizer==3.4.1
click==8.1.8
coverage==7.2.7
exceptiongroup==1.2.2
flake8==5.0.4
-e git+https://github.com/googleapis/google-resumable-media-python.git@434828b00db2c72e7f67a0c5628cde2c3f87aeb4#egg=google_resumable_media
idna==3.10
importlib-metadata==4.2.0
iniconfig==2.0.0
mccabe==0.7.0
mock==5.2.0
mypy-extensions==1.0.0
packaging==24.0
pathspec==0.11.2
platformdirs==4.0.0
pluggy==1.2.0
pycodestyle==2.9.1
pyflakes==2.5.0
pytest==7.4.4
pytest-cov==4.1.0
requests==2.31.0
six==1.17.0
sphinx-docstring-typing==0.0.4
tomli==2.0.1
typed-ast==1.5.5
typing_extensions==4.7.1
urllib3==2.0.7
zipp==3.15.0

name: google-resumable-media-python
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - black==23.3.0
      - charset-normalizer==3.4.1
      - click==8.1.8
      - coverage==7.2.7
      - exceptiongroup==1.2.2
      - flake8==5.0.4
      - idna==3.10
      - importlib-metadata==4.2.0
      - iniconfig==2.0.0
      - mccabe==0.7.0
      - mock==5.2.0
      - mypy-extensions==1.0.0
      - packaging==24.0
      - pathspec==0.11.2
      - platformdirs==4.0.0
      - pluggy==1.2.0
      - pycodestyle==2.9.1
      - pyflakes==2.5.0
      - pytest==7.4.4
      - pytest-cov==4.1.0
      - requests==2.31.0
      - six==1.17.0
      - sphinx-docstring-typing==0.0.4
      - tomli==2.0.1
      - typed-ast==1.5.5
      - typing-extensions==4.7.1
      - urllib3==2.0.7
      - zipp==3.15.0
prefix: /opt/conda/envs/google-resumable-media-python

tests/unit/test__upload.py::Test_get_next_chunk::test_success_known_size_lt_stream_size
tests/unit/test__upload.py::TestUploadBase::test_constructor_defaults tests/unit/test__upload.py::TestUploadBase::test_constructor_explicit tests/unit/test__upload.py::TestUploadBase::test_finished_property tests/unit/test__upload.py::TestUploadBase::test__process_response_bad_status tests/unit/test__upload.py::TestUploadBase::test__process_response tests/unit/test__upload.py::TestUploadBase::test__get_status_code tests/unit/test__upload.py::TestUploadBase::test__get_headers tests/unit/test__upload.py::TestUploadBase::test__get_body tests/unit/test__upload.py::TestSimpleUpload::test__prepare_request_already_finished tests/unit/test__upload.py::TestSimpleUpload::test__prepare_request_non_bytes_data tests/unit/test__upload.py::TestSimpleUpload::test__prepare_request tests/unit/test__upload.py::TestSimpleUpload::test__prepare_request_with_headers tests/unit/test__upload.py::TestSimpleUpload::test_transmit tests/unit/test__upload.py::TestMultipartUpload::test__prepare_request_already_finished tests/unit/test__upload.py::TestMultipartUpload::test__prepare_request_non_bytes_data tests/unit/test__upload.py::TestMultipartUpload::test__prepare_request tests/unit/test__upload.py::TestMultipartUpload::test__prepare_request_with_headers tests/unit/test__upload.py::TestMultipartUpload::test_transmit tests/unit/test__upload.py::TestResumableUpload::test_constructor tests/unit/test__upload.py::TestResumableUpload::test_constructor_bad_chunk_size tests/unit/test__upload.py::TestResumableUpload::test_invalid_property tests/unit/test__upload.py::TestResumableUpload::test_chunk_size_property tests/unit/test__upload.py::TestResumableUpload::test_resumable_url_property tests/unit/test__upload.py::TestResumableUpload::test_bytes_uploaded_property tests/unit/test__upload.py::TestResumableUpload::test_total_bytes_property tests/unit/test__upload.py::TestResumableUpload::test__prepare_initiate_request tests/unit/test__upload.py::TestResumableUpload::test__prepare_initiate_request_with_headers tests/unit/test__upload.py::TestResumableUpload::test__prepare_initiate_request_known_size tests/unit/test__upload.py::TestResumableUpload::test__prepare_initiate_request_unknown_size tests/unit/test__upload.py::TestResumableUpload::test__prepare_initiate_request_already_initiated tests/unit/test__upload.py::TestResumableUpload::test__prepare_initiate_request_bad_stream_position tests/unit/test__upload.py::TestResumableUpload::test__process_initiate_response_non_200 tests/unit/test__upload.py::TestResumableUpload::test__process_initiate_response tests/unit/test__upload.py::TestResumableUpload::test_initiate tests/unit/test__upload.py::TestResumableUpload::test__prepare_request_already_finished tests/unit/test__upload.py::TestResumableUpload::test__prepare_request_invalid tests/unit/test__upload.py::TestResumableUpload::test__prepare_request_not_initiated tests/unit/test__upload.py::TestResumableUpload::test__prepare_request_invalid_stream_state tests/unit/test__upload.py::TestResumableUpload::test__prepare_request_success tests/unit/test__upload.py::TestResumableUpload::test__prepare_request_success_with_headers tests/unit/test__upload.py::TestResumableUpload::test__make_invalid tests/unit/test__upload.py::TestResumableUpload::test__process_response_bad_status tests/unit/test__upload.py::TestResumableUpload::test__process_response_success tests/unit/test__upload.py::TestResumableUpload::test__process_response_partial_no_range tests/unit/test__upload.py::TestResumableUpload::test__process_response_partial_bad_range tests/unit/test__upload.py::TestResumableUpload::test__process_response_partial tests/unit/test__upload.py::TestResumableUpload::test_transmit_next_chunk tests/unit/test__upload.py::TestResumableUpload::test__prepare_recover_request_not_invalid tests/unit/test__upload.py::TestResumableUpload::test__prepare_recover_request tests/unit/test__upload.py::TestResumableUpload::test__prepare_recover_request_with_headers tests/unit/test__upload.py::TestResumableUpload::test__process_recover_response_bad_status tests/unit/test__upload.py::TestResumableUpload::test__process_recover_response_no_range tests/unit/test__upload.py::TestResumableUpload::test__process_recover_response_bad_range tests/unit/test__upload.py::TestResumableUpload::test__process_recover_response_with_range tests/unit/test__upload.py::TestResumableUpload::test_recover tests/unit/test__upload.py::test_get_boundary tests/unit/test__upload.py::Test_construct_multipart_request::test_binary tests/unit/test__upload.py::Test_construct_multipart_request::test_unicode tests/unit/test__upload.py::test_get_total_bytes tests/unit/test__upload.py::Test_get_next_chunk::test_exhausted_known_size tests/unit/test__upload.py::Test_get_next_chunk::test_exhausted_known_size_zero tests/unit/test__upload.py::Test_get_next_chunk::test_exhausted_known_size_zero_nonempty tests/unit/test__upload.py::Test_get_next_chunk::test_success_known_size tests/unit/test__upload.py::Test_get_next_chunk::test_success_unknown_size tests/unit/test__upload.py::Test_get_content_range::test_known_size tests/unit/test__upload.py::Test_get_content_range::test_unknown_size
google/resumable_media/_upload.py
google/resumable_media/_upload.py