Skip to content

du: block size parsing #7738

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

Open
1 of 3 tasks
BenWiederhake opened this issue Apr 12, 2025 · 1 comment
Open
1 of 3 tasks

du: block size parsing #7738

BenWiederhake opened this issue Apr 12, 2025 · 1 comment
Labels

Comments

@BenWiederhake
Copy link
Collaborator

BenWiederhake commented Apr 12, 2025

  • -B0 shouldn't panic. I think this should win some kind of "panic golf" :)
  • 1000 and kb and 1024 and k should result in different output, but parse_size_u64 causes information loss (i.e. does not return whether a multiplier was used).
  • 0b11 should be accepted (and interpreted as 3), but determine_number_system does not recognize that prefix.

I think I'll fix this myself soon-ish, but wanted to documented it first, in case I forget about it.

@BenWiederhake
Copy link
Collaborator Author

More cursed invocations so that I don't forget:

BLOCK_SIZE=' 10' du --apparent-size README.md # 10
BLOCK_SIZE='10garbage' du --apparent-size README.md # 3G
BLOCK_SIZE='10MB' du --apparent-size README.md # 10MB
BLOCK_SIZE='10mB' du --apparent-size README.md # 10MB
BLOCK_SIZE='10mb' du --apparent-size README.md # 10MB
du --apparent-size -B 10KB README.md # 10KB
du --apparent-size -B 10kB README.md # 10KB
du --apparent-size -B 10MB README.md # 10MB
du --apparent-size -B 10mB README.md # 10MB
du --apparent-size -B 10mb README.md # error (sigh)
BLOCK_SIZE='10mib' du --apparent-size README.md # 10M
du --apparent-size -B 10mib README.md # error (sigh)
BLOCK_SIZE='10PiB' du --apparent-size README.md # 10P
BLOCK_SIZE='10piB' du --apparent-size README.md # 10 (lol)
du --apparent-size -B 10PiB README.md # 10P
du --apparent-size -B 10piB README.md # error
BLOCK_SIZE=' 10' du --apparent-size README.md # leading space should be trimmed
BLOCK_SIZE=$'\v10' du --apparent-size README.md # leading space should be trimmed, even though trim_ascii doesn't recognize it
BLOCK_SIZE=$'\xc2\xa03' du --apparent-size README.md # leading space should NOT be trimmed, even though trim_start would remove it
BLOCK_SIZE='3garbage' du --apparent-size README.md # 3g
BLOCK_SIZE='99999999TB' du --apparent-size README.md # Saturates!
dd if=/dev/zero of=/dev/null count=1 $'bs=\v10' # allows whitespace
dd if=/dev/zero of=/dev/null count=1 bs=0 # shouldn't crash (sigh)
dd if=/dev/zero of=/dev/null count=0b100 bs=1 # Doesn't support binary!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant