From 48c4c15e4e55af0ebe4cd52d8c598f21fc6efb3e Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 5 Aug 2026 15:31:04 +0200 Subject: [PATCH] tests: numfmt: add checks for overflowing unit sizes * tests/numfmt/numfmt.pl (@Tests): Add unit-11 and unit-12, ensuring a --to-unit/--from-unit whose suffix multiplication overflows uintmax_t is rejected with "invalid unit size" rather than being wrapped or crashing. Link: https://github.com/uutils/coreutils/pull/13484 Link: https://github.com/coreutils/coreutils/pull/326 --- tests/numfmt/numfmt.pl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/numfmt/numfmt.pl b/tests/numfmt/numfmt.pl index 827d5ea3f..ea52d2b25 100755 --- a/tests/numfmt/numfmt.pl +++ b/tests/numfmt/numfmt.pl @@ -115,6 +115,15 @@ my @Tests = ['unit-10', '--to-unit=0 1', {ERR => "$prog: invalid unit size: '0'\n"}, {EXIT => '1'}], + # Ensure a unit size whose suffix multiplication overflows uintmax_t + # is rejected. 18014398509481984Ki is 2^54. + # Multiplying by Ki (2^10) overflows to UINTMAX_MAX + 1. + ['unit-11', '--to-unit=18014398509481984Ki 1000', + {ERR => "$prog: invalid unit size: '18014398509481984Ki'\n"}, + {EXIT => '1'}], + ['unit-12', '--from-unit='.$limits->{UINTMAX_MAX}.'K 1', + {ERR => "$prog: invalid unit size: '$limits->{UINTMAX_MAX}K'\n"}, + {EXIT => '1'}], # Test Suffix logic ['suf-1', '4000', {OUT=>'4000'}],