Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer overflow with huge files #58

Closed
Freaky opened this issue Jun 30, 2020 · 4 comments
Closed

Integer overflow with huge files #58

Freaky opened this issue Jun 30, 2020 · 4 comments

Comments

@Freaky
Copy link
Contributor

Freaky commented Jun 30, 2020

When faced with file sizes that sum beyond the limits of a u64, such as:

.rw-r--r-- 9.2E freaky freaky 29 Jun 21:48 huge1
.rw-r--r-- 9.2E freaky freaky 29 Jun 21:49 huge2
.rw-r--r-- 9.2E freaky freaky 29 Jun 21:49 huge3
.rw-r--r-- 9.2E freaky freaky 29 Jun 21:49 huge4

dua -A in debug mode panics:

thread 'main' panicked at 'attempt to add with overflow', /home/freaky/code/dua-cli-freaky/src/aggregate.rs:60:21

And produces incorrect results in release builds:

  18.45 EB huge

Not really worse than most other similar tools - GNU du just gives up and declares the size infinite, and BSD du seems to believe negative file sizes are possible - but perhaps it would be nice to Just Work, given Rust's u128 support.

@Byron
Copy link
Owner

Byron commented Jul 1, 2020

You have just shattered my idea that nobody, ever, would hit the limits of u64, who can fit the amount of stars in the known universe multiple times and all :D. Probably that idea of mines is quite similar to that other one, along the lines of "640kb of main memory is going to be enough" :D.

Out of curousity: How did you produce these files? Are they actually backed by that much disk space?

To the point: I think it would not be an issue to represent the final aggregation as u128.
Would you be interested in giving that a shot?

@Freaky
Copy link
Contributor Author

Freaky commented Jul 1, 2020

 ❯ truncate -s 9223372036854775807 huge1
 ❯ l huge1
.rw-r--r-- 9.2E freaky freaky  1 Jul 15:56 huge1

They're sparse files and consume no more space than an empty file.

I'll have a look and see if I get bored before I finish fixing the compiler errors ;)

Freaky added a commit to Freaky/dua-cli that referenced this issue Jul 1, 2020
Per issue Byron#58, u64 is insufficient for use with very large sparse files.
Enormous file sizes are also a common filesystem error trope, either
from disk corruption or software bugs, and they're also conceivable with
virtual filesystems.

Handle this as gracefully as can be reasonably expected using 128-bit
integers, which should be sufficient for most uses.
@Freaky
Copy link
Contributor Author

Freaky commented Jul 1, 2020

Test environment:

 ❯ truncate -s 9223372036854775807 huge/{1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}

Before:

 ❯ dua -A huge
  18.45 EB huge

After:

❯ dua -A huge
   8.30 ZB huge

Byron pushed a commit that referenced this issue Jul 1, 2020
Per issue #58, u64 is insufficient for use with very large sparse files.
Enormous file sizes are also a common filesystem error trope, either
from disk corruption or software bugs, and they're also conceivable with
virtual filesystems.

Handle this as gracefully as can be reasonably expected using 128-bit
integers, which should be sufficient for most uses.
@Byron
Copy link
Owner

Byron commented Jul 1, 2020

Wonderful! I wasn't aware that truncate could also create files - thus far I was just using it for removing a trailing newlines using -s -1 😅.
Amazing.

Closing this issue as the PR fixing it was merged.

@Byron Byron closed this as completed Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants