uutils/coreutils · error · io::Error

OutOfMemory

OutOfMemory

Error message

formatting width too large

What it means

Error "formatting width too large" thrown in uutils/coreutils.

Source

Thrown at src/uucore/src/lib/features/format/mod.rs:182

                "digits" => String::from_utf8_lossy(digits)
            ),
            Self::InvalidEncoding(no) => return no.fmt(f),
        };
        f.write_str(&message)
    }
}

/// Maximum width for formatting to prevent memory allocation panics.
/// Rust's formatter will panic when trying to allocate memory for very large widths.
/// This limit is somewhat arbitrary but should be well above any practical use case
/// while still preventing formatter panics.
const MAX_FORMAT_WIDTH: usize = 1_000_000;

/// Check if a width is too large for formatting.
/// Returns an error if the width exceeds MAX_FORMAT_WIDTH.
fn check_width(width: usize) -> std::io::Result<()> {
    if width > MAX_FORMAT_WIDTH {
        Err(std::io::Error::new(
            std::io::ErrorKind::OutOfMemory,
            "formatting width too large",
        ))
    } else {
        Ok(())
    }
}

/// Reject a precision larger than printf/C allows (`i32::MAX`).
///
/// A precision near `usize::MAX` would otherwise overflow the precision/exponent
/// arithmetic in the float formatters, so we cap it the way C `printf` does.
pub(crate) fn check_precision(precision: usize) -> Result<(), FormatError> {
    if precision > i32::MAX as usize {
        Err(FormatError::InvalidPrecision(precision.to_string()))
    } else {
        Ok(())
    }

View on GitHub (pinned to 85295bbf78)

Solutions

  1. Reduce the field width/precision in the format specification to a reasonable value.
  2. Validate user-supplied width arguments against a sane upper bound before formatting.

When it happens

Trigger: Occurs when a printf-style format width specifier exceeds the maximum supported value.

Common situations: Using an extremely large field width like `printf '%999999999999d'` or a width derived from untrusted input.


AI-assisted analysis of uutils/coreutils@85295bbf78 (2026-08-19). Data as JSON: /api/errors/824f886d7cdbda7f. Report an issue: GitHub.