[GH-ISSUE #857] FileChunk Int32 overflow #582

Closed
opened 2026-02-27 15:50:59 +03:00 by kerem · 1 comment
Owner

Originally created by @devcore256 on GitHub (Jul 27, 2020).
Original GitHub issue: https://github.com/quasar/Quasar/issues/857

Description
File downloading is not work correctly for files larger than Int32.MaxValue (2147483647 bytes). You will get error message from client "Error reading file" when you try _fileStream.Seek(offset, SeekOrigin.Begin); in method ReadChunk(long offset).

Bug in class Quasar.Common.IO.FileSplit

public IEnumerator<FileChunk> GetEnumerator()
        {
            for (int currentChunk = 0; currentChunk <= _fileStream.Length / MaxChunkSize; currentChunk++)
            {
                yield return ReadChunk(currentChunk * MaxChunkSize);
            }
        }

When pass arg to ReadChunk method currentChunk * MaxChunkSize is casting to Int32. We must declare currentChunk as long.

Expected behavior

public IEnumerator<FileChunk> GetEnumerator()
        {
            for (long currentChunk = 0; currentChunk <= _fileStream.Length / MaxChunkSize; currentChunk++)
            {
                yield return ReadChunk(currentChunk * MaxChunkSize);
            }
        }
Originally created by @devcore256 on GitHub (Jul 27, 2020). Original GitHub issue: https://github.com/quasar/Quasar/issues/857 **Description** File downloading is not work correctly for files larger than Int32.MaxValue (**2147483647 bytes**). You will get error message from client "Error reading file" when you try `_fileStream.Seek(offset, SeekOrigin.Begin);` in method ReadChunk(long offset). Bug in class **Quasar.Common.IO.FileSplit** ``` public IEnumerator<FileChunk> GetEnumerator() { for (int currentChunk = 0; currentChunk <= _fileStream.Length / MaxChunkSize; currentChunk++) { yield return ReadChunk(currentChunk * MaxChunkSize); } } ``` When pass arg to ReadChunk method currentChunk * MaxChunkSize is casting to Int32. We must declare currentChunk as **long**. **Expected behavior** ``` public IEnumerator<FileChunk> GetEnumerator() { for (long currentChunk = 0; currentChunk <= _fileStream.Length / MaxChunkSize; currentChunk++) { yield return ReadChunk(currentChunk * MaxChunkSize); } } ```
kerem 2026-02-27 15:50:59 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@MaxXor commented on GitHub (Aug 8, 2020):

Nice catch and very detailed error report. Thanks a lot!

<!-- gh-comment-id:670905914 --> @MaxXor commented on GitHub (Aug 8, 2020): Nice catch and very detailed error report. Thanks a lot!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Quasar#582
No description provided.