nathanhi / pyfatfs

Python based FAT12/FAT16/FAT32 implementation with VFAT support
https://pypi.org/project/pyfatfs/
MIT License
29 stars 14 forks source link

File sizes >4GB are not handled gracefully #31

Closed nathanhi closed 7 months ago

nathanhi commented 1 year ago

If a file with >4GB in size is created struct.pack throws an exception while trying to pack the size:


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nathanhi/src/pyfatfs/.venv/lib/python3.11/site-packages/fs/copy.py", line 144, in copy_file
    copy_file_if(
  File "/home/nathanhi/src/pyfatfs/.venv/lib/python3.11/site-packages/fs/copy.py", line 223, in copy_file_if
    copy_file_internal(
  File "/home/nathanhi/src/pyfatfs/.venv/lib/python3.11/site-packages/fs/copy.py", line 279, in copy_file_internal
    _copy_locked()
  File "/home/nathanhi/src/pyfatfs/.venv/lib/python3.11/site-packages/fs/copy.py", line 272, in _copy_locked
    dst_fs.upload(dst_path, read_file)
  File "/home/nathanhi/src/pyfatfs/.venv/lib/python3.11/site-packages/fs/base.py", line 1417, in upload
    tools.copy_file_data(file, dst_file, chunk_size=chunk_size)
  File "/home/nathanhi/src/pyfatfs/.venv/lib/python3.11/site-packages/fs/tools.py", line 54, in copy_file_data
    write(chunk)
  File "/home/nathanhi/src/pyfatfs/pyfatfs/FatIO.py", line 200, in write
    self.fs.update_directory_entry(self.dir_entry.get_parent_dir())
  File "/home/nathanhi/src/pyfatfs/pyfatfs/__init__.py", line 25, in _wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/nathanhi/src/pyfatfs/pyfatfs/PyFat.py", line 34, in _wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/nathanhi/src/pyfatfs/pyfatfs/PyFat.py", line 595, in update_directory_entry
    dir_entries += bytes(d)
                   ^^^^^^^^
  File "/home/nathanhi/src/pyfatfs/pyfatfs/FATDirectoryEntry.py", line 247, in __bytes__
    entry += struct.pack(self.FAT_DIRECTORY_LAYOUT,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: 'L' format requires 0 <= number <= 4294967295```

Instead, a PyFatException with errno `EFBIG` should be raised