fix(tui): add MAX_WRAP_INPUT_LEN guard to prevent UI freeze on oversized lines (closes #26)
- compute_line_entry/compute_visual_height: double guard (raw + post-format) - Skip detect_level on oversized raw input to avoid O(n) JSON parsing - Add post-format guard for JSON lines that expand beyond 10MB - progressive_reader: add post-format guard to compute_line_visual_height - Add truncate_to_columns helper using existing wrap_line_chars - Fix misleading docstring on MAX_WRAP_INPUT_LEN constant - Add 6 regression tests covering all guard paths
This commit is contained in:
@@ -223,6 +223,9 @@ pub fn compute_line_visual_height(
|
||||
}
|
||||
if json_format {
|
||||
let formatted = format_json_line(line_text);
|
||||
if formatted.len() > MAX_WRAP_INPUT_LEN {
|
||||
return 1;
|
||||
}
|
||||
compute_text_visual_height(&formatted, terminal_width)
|
||||
} else {
|
||||
compute_text_visual_height(line_text, terminal_width)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/// Maximum input length for wrap/format operations (10 MB).
|
||||
/// Lines exceeding this are returned as-is to avoid pathological cases.
|
||||
/// Callers should check against this constant before invoking `wrap_line_chars`
|
||||
/// to avoid pathological cases on oversized lines.
|
||||
pub const MAX_WRAP_INPUT_LEN: usize = 10 * 1024 * 1024;
|
||||
|
||||
/// Split a line into chunks of exactly `width` display columns.
|
||||
|
||||
Reference in New Issue
Block a user