Skip to content

Commit fbedfa8

Browse files
committed
fix(awk): reject oversized single output writes
1 parent 5d6cb63 commit fbedfa8

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

crates/bashkit/src/builtins/awk/interpreter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ impl AwkInterpreter {
10001000
}
10011001

10021002
fn has_output_capacity(&self, len: usize) -> bool {
1003-
self.total_output_bytes <= MAX_AWK_OUTPUT_BYTES.saturating_sub(len)
1003+
len <= MAX_AWK_OUTPUT_BYTES.saturating_sub(self.total_output_bytes)
10041004
}
10051005

10061006
fn output_target_count(&self) -> usize {

crates/bashkit/src/builtins/awk/tests.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::{Awk, csv_split_fields};
55
use crate::builtins::limits::{
66
AWK_MAX_GETLINE_CACHE_BYTES as MAX_GETLINE_CACHE_BYTES,
77
AWK_MAX_GETLINE_CACHED_FILES as MAX_GETLINE_CACHED_FILES,
8-
AWK_MAX_GETLINE_FILE_BYTES as MAX_GETLINE_FILE_BYTES,
8+
AWK_MAX_GETLINE_FILE_BYTES as MAX_GETLINE_FILE_BYTES, AWK_MAX_OUTPUT_BYTES as MAX_OUTPUT_BYTES,
99
AWK_MAX_OUTPUT_TARGETS as MAX_OUTPUT_TARGETS,
1010
};
1111
use crate::builtins::{Builtin, Context};
@@ -947,6 +947,20 @@ async fn test_awk_output_limit_exceeded() {
947947
);
948948
}
949949

950+
#[tokio::test]
951+
async fn test_awk_single_write_over_limit_rejected() {
952+
// One oversized record must be rejected before buffering stdout.
953+
let input = "x".repeat(MAX_OUTPUT_BYTES);
954+
let result = run_awk(&["{ print }"], Some(&input)).await.unwrap();
955+
assert_eq!(result.exit_code, 2);
956+
assert!(
957+
result.stderr.contains("output limit exceeded"),
958+
"stderr should mention output limit: {}",
959+
result.stderr
960+
);
961+
assert_eq!(result.stdout.len(), 0);
962+
}
963+
950964
#[tokio::test]
951965
async fn test_awk_output_under_limit_ok() {
952966
// Small output well under 10MB should succeed normally

0 commit comments

Comments
 (0)