JustinBinber opened a new issue, #41621:
URL: https://github.com/apache/beam/issues/41621

   ### What happened?
   
   One-shot reads of compressed files can silently return only the first 16 
MiB. This affects `FileSystems.open(path).read()`, `fileio.ReadableFile.read()` 
and `read_utf8()`; the equivalent uncompressed file is read completely.
   
   A local reproduction on current master 
(`9c564f9d95b0d3a3cd59d60a457a99351b08e539`, Python 3.11.7 on Windows):
   
   ```python
   import gzip
   import os
   import tempfile
   from apache_beam.io.filesystems import FileSystems
   
   with tempfile.TemporaryDirectory() as directory:
       path = os.path.join(directory, "input.gz")
       first = b"a" * (16 * 1024 * 1024)
       tail = b"last row\n"
       with open(path, "wb") as output:
           output.write(gzip.compress(first) + gzip.compress(tail))
       with FileSystems.open(path) as source:
           data = source.read()
           print(len(data), len(first) + len(tail))
           print(source.read())
   ```
   
   Actual output:
   
   ```
   16777216 16777225
   b'last row\n'
   ```
   
   The first read should include the final row. `CompressedFile.read()` 
defaults to `DEFAULT_READ_BUFFER_SIZE`, and its internal fetch stops as soon as 
this many decompressed bytes are buffered. Callers performing one read receive 
no indication that more data remains.
   
   Explicit unlimited sizes are also broken for all five supported codecs 
(gzip, deflate, bzip2, zstd, lzma): `read(-1)` returns empty bytes on a fresh 
file, and `read(None)` raises `TypeError` while comparing a byte count to 
`None`.
   
   Expected: omitted, `None` and negative sizes read all remaining decompressed 
content, as ordinary binary files do; explicit nonnegative sizes retain bounded 
behavior. I plan to address this in the shared compressed buffer logic, with 
regression tests for the public readers, all five codecs, concatenated members, 
and seek/position behavior.
   
   Related: #34435 / #34475 changed the default to avoid an exception but did 
not implement unlimited reads. This is separate from #41471 / #41472, where the 
CSV source restriction uses compressed file size.
   
   ### Issue Priority
   
   Priority: 1 (data loss / total loss of function)
   
   ### Issue Components
   
   - [x] Component: Python SDK
   - [x] Component: IO connector
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to