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

Android 12: df fix integer overflow in computation of Total row #6070

Closed
cre4ture opened this issue Mar 14, 2024 · 0 comments · Fixed by #6071
Closed

Android 12: df fix integer overflow in computation of Total row #6070

cre4ture opened this issue Mar 14, 2024 · 0 comments · Fixed by #6071
Labels

Comments

@cre4ture
Copy link
Contributor

I create this issue from a finding from pullrequest #5821.

When running tests of uutils df on my own android phone (not on AVD),
they are failing due to integer overflow:

---- test_df::test_default_block_size stdout ----
run: /data/data/com.termux/files/home/rust/coreutils/target/debug/coreutils df --output=size
thread 'test_df::test_default_block_size' panicked at tests/by-util/test_df.rs:485:10:
Command was expected to succeed. Exit code: 101.
stdout = 
 stderr = thread 'main' panicked at src/uu/df/src/table.rs:105:22:
attempt to add with overflow

The fix that I'm working on in PR #5821 can handle this and the result is:

~/rust/coreutils $ target/debug/coreutils df -Ti --total
Filesystem                             Type                   Inodes  IUsed                IFree IUse% Mounted on
/dev/block/dm-15                       erofs    18446744073709551615   3141 18446744073709548474    1% /
tmpfs                                  tmpfs                 1457181   1460              1455721    1% /dev
tmpfs                                  tmpfs                 1457181     65              1457116    1% /mnt
/dev/block/by-name/metadata            ext4                     4096     34                 4062    1% /metadata
/dev/block/dm-16                       erofs    18446744073709551615   3002 18446744073709548613    1% /system_ext
/dev/block/dm-17                       ext4                      304    298                    6   99% /product
overlay-overlay                        overlay  18446744073709551615      0 18446744073709551615    0% /product/app
overlay-overlay                        overlay  18446744073709551615      0 18446744073709551615    0% /product/priv-app
overlay-overlay                        overlay  18446744073709551615      0 18446744073709551615    0% /product/lib64
overlay-overlay                        overlay  18446744073709551615      0 18446744073709551615    0% /product/lib
overlay-overlay                        overlay  18446744073709551615      0 18446744073709551615    0% /product/overlay
overlay                                overlay  18446744073709551615      0 18446744073709551615    0% /product/etc/permissions
overlay                                overlay  18446744073709551615      0 18446744073709551615    0% /product/framework
/dev/block/dm-18                       erofs    18446744073709551615      0 18446744073709551615    0% /vendor
/dev/block/dm-19                       erofs    18446744073709551615      0 18446744073709551615    0% /odm
/dev/block/dm-20                       erofs    18446744073709551615      0 18446744073709551615    0% /my_product
/dev/block/dm-21                       erofs    18446744073709551615      0 18446744073709551615    0% /my_engineering
/dev/block/dm-23                       erofs    18446744073709551615      0 18446744073709551615    0% /my_carrier
/dev/block/dm-24                       erofs    18446744073709551615      0 18446744073709551615    0% /my_region
/dev/block/dm-25                       erofs    18446744073709551615      0 18446744073709551615    0% /my_heytap
/dev/block/dm-26                       erofs    18446744073709551615      0 18446744073709551615    0% /my_stock
/dev/block/dm-27                       erofs    18446744073709551615      0 18446744073709551615    0% /my_preload
/dev/block/dm-28                       erofs    18446744073709551615      0 18446744073709551615    0% /my_bigball
/dev/block/dm-29                       erofs    18446744073709551615      0 18446744073709551615    0% /my_manifest
tmpfs                                  tmpfs                 1457181     70              1457111    1% /apex
/dev/block/loop5                       ext4                       32     20                   12   63% /apex/com.android.apex.cts.shim@1
/dev/block/loop5                       ext4                       32     20                   12   63% /apex/com.android.apex.cts.shim
/dev/block/loop6                       ext4                       32     23                    9   72% /apex/com.android.appsearch@300000000
/dev/block/loop7                       ext4                       48     35                   13   73% /apex/com.android.i18n@1
/dev/block/loop6                       ext4                       32     23                    9   72% /apex/com.android.appsearch
/dev/block/loop7                       ext4                       48     35                   13   73% /apex/com.android.i18n
/dev/block/loop8                       ext4                       32     29                    3   91% /apex/com.android.wifi@319999900
/dev/block/loop8                       ext4                       32     29                    3   91% /apex/com.android.wifi
/dev/block/loop11                      ext4                      304    290                   14   96% /apex/com.android.vndk.v31@1
/dev/block/loop11                      ext4                      304    290                   14   96% /apex/com.android.vndk.v31
/dev/block/dm-31                       ext4                      112    112                    0  100% /apex/com.android.art@341311100
/dev/block/dm-31                       ext4                      112    112                    0  100% /apex/com.android.art
/dev/block/dm-32                       ext4                       32     28                    4   88% /apex/com.android.permission@341311000
/dev/block/dm-30                       ext4                       32     25                    7   79% /apex/com.android.extservices@341317010
/dev/block/dm-32                       ext4                       32     28                    4   88% /apex/com.android.permission
/dev/block/dm-30                       ext4                       32     25                    7   79% /apex/com.android.extservices
/dev/block/dm-33                       ext4                      176    167                    9   95% /apex/com.android.conscrypt@341310090
/dev/block/loop15                      ext4                       64     50                   14   79% /apex/com.android.runtime@1
/dev/block/dm-33                       ext4                      176    167                    9   95% /apex/com.android.conscrypt
/dev/block/loop16                      ext4                      608    596                   12   99% /apex/com.android.vndk.v30@1
/dev/block/loop15                      ext4                       64     50                   14   79% /apex/com.android.runtime
/dev/block/loop16                      ext4                      608    596                   12   99% /apex/com.android.vndk.v30
/dev/block/dm-34                       ext4                       32     20                   12   63% /apex/com.android.tzdata@314012010
/dev/block/dm-34                       ext4                       32     20                   12   63% /apex/com.android.tzdata
/dev/block/dm-37                       ext4                       64     58                    6   91% /apex/com.android.media@341312020
/dev/block/dm-37                       ext4                       64     58                    6   91% /apex/com.android.media
/dev/block/dm-36                       ext4                       32     20                   12   63% /apex/com.android.scheduling@340819220
/dev/block/dm-36                       ext4                       32     20                   12   63% /apex/com.android.scheduling
/dev/block/dm-35                       ext4                       32     31                    1   97% /apex/com.android.os.statsd@341410000
/dev/block/dm-35                       ext4                       32     31                    1   97% /apex/com.android.os.statsd
/dev/block/dm-38                       ext4                       32     27                    5   85% /apex/com.android.mediaprovider@341313030
/dev/block/dm-38                       ext4                       32     27                    5   85% /apex/com.android.mediaprovider
/dev/block/dm-39                       ext4                       48     36                   12   75% /apex/com.android.adbd@340912350
/dev/block/dm-39                       ext4                       48     36                   12   75% /apex/com.android.adbd
/dev/block/dm-40                       ext4                      128    114                   14   90% /apex/com.android.media.swcodec@341312020
/dev/block/dm-40                       ext4                      128    114                   14   90% /apex/com.android.media.swcodec
/dev/block/dm-41                       ext4                       16     16                    0  100% /apex/com.android.neuralnetworks@341010080
/dev/block/dm-41                       ext4                       16     16                    0  100% /apex/com.android.neuralnetworks
/dev/block/loop27                      ext4                       32     26                    6   82% /apex/com.google.mainline.primary.libs@331059000
/dev/block/dm-42                       ext4                       32     21                   11   66% /apex/com.android.cellbroadcast@341311010
/dev/block/dm-42                       ext4                       32     21                   11   66% /apex/com.android.cellbroadcast
/dev/block/dm-43                       ext4                       32     20                   12   63% /apex/com.android.ipsec@340914280
/dev/block/dm-43                       ext4                       32     20                   12   63% /apex/com.android.ipsec
/dev/block/dm-44                       ext4                       80     73                    7   92% /apex/com.android.tethering@341310230
/dev/block/dm-44                       ext4                       80     73                    7   92% /apex/com.android.tethering
/dev/block/dm-45                       ext4                       32     26                    6   82% /apex/com.google.mainline.primary.libs@341339070
/dev/block/dm-46                       ext4                       16     16                    0  100% /apex/com.android.resolv@341311030
/dev/block/dm-46                       ext4                       16     16                    0  100% /apex/com.android.resolv
/dev/block/dm-47                       ext4                       32     24                    8   75% /apex/com.android.sdkext@341110080
/dev/block/dm-47                       ext4                       32     24                    8   75% /apex/com.android.sdkext
/dev/block/bootdevice/by-name/cache    ext4                   114688     55               114633    1% /cache
/dev/block/bootdevice/by-name/userdata f2fs                 12812797 347711             12465086    3% /data
/dev/fuse                              fuse                 12812797 347711             12465086    3% /storage/emulated
/data/media                            sdcardfs             12812797 347711             12465086    3% /storage/emulated/0/Android/data
/data/media                            sdcardfs             12812797 347711             12465086    3% /storage/emulated/0/Android/obb
total                                  -        368934881474246778279 1402723 368934881474245375556    1% -
~/rust/coreutils $ 

One can see that some entries (of type erofs) report inodes number at exactly (or close to) 18446744073709551615 which is the maximum number a u64 can represent.
I also tested the GNU implementation for this (on a erofs on my ubuntu) and it turned out that GNU also is not handling it porperly. It does a silent integer (u64) overflow in this case.

Therefor my proposal is to use a u128 for the total sum of inodes. I know that this is slower than u64 as its probably not natively supported, but we are not accululating millions of numbers such that it should not be significant.

I will continue working on it and provide a seperate PR to #5821

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

Successfully merging a pull request may close this issue.

2 participants