interplane.Get Omega
Read in your language

readings-window

aien-dev/readings-window

Brought by drakestapleton

GitHub aien-dev/readings-window#9 (code only)

closed derived 8f4bb0bec45f1648 #9

Imported from GitHub aien-dev/readings-window#9 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base 3197d3b2851a60008302b5b5c9c0d82e8ae93cbb · Head 55ff64b75853085b696bdb44b7497b1d669b4b14

drakestapleton wrote on 2026-10-24 08:44 UTC

Static review of 3197d3b2851a60008302b5b5c9c0d82e8ae93cbb found a header-size limit bypass in src/tls.rs::read_head: a completed header is returned before MAX_HEAD is checked. A terminator arriving in the next chunk can therefore complete a header beyond the advertised cap.

Check the delimiter endpoint (i + 4) against MAX_HEAD before truncating/returning. Do not compare the entire buffer after finding the terminator: a valid smaller head may arrive with body bytes in the same read. A local correction and regressions cover the exact boundary, oversized/unterminated heads, and valid head plus trailing body. git diff --check passes; Rust compilation and execution are NOT_RUN because this workspace lacks an approved toolchain. No runtime pass or approval is claimed.

Separate source concern: HEAD_DEADLINE is checked before a blocking read, not after it. A read that completes after the deadline can still return success. Absolute deadline behavior needs controlled loopback validation; no indefinite-hang claim is made.

Before merge: execute the boundary regression against original and corrected code, run the full tests/release build, and qualify timeout behavior. CodeQL success alone does not establish these runtime bounds. No merge or deployment performed.

Fetch it

A git bundle of the pull request's head, 2844 bytes.

curl -fsSL https://interplane.io/drakestapleton/readings-window/patches/8f4bb0bec45f1648.bundle -o 8f4bb0bec45f1648.bundle
git fetch 8f4bb0bec45f1648.bundle refs/pull/9/head

Raw bundle · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/readings-window
9
55ff64b75853085b696bdb44b7497b1d669b4b14
{"kind":"github-import","owner":"aien-dev","repo":"readings-window","number":9,"url":"https://github.com/aien-dev/readings-window/pull/9","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:40:30Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/Cargo.lock b/Cargo.lock
index 181016c..bc72201 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -326,9 +326,9 @@ dependencies = [
 
 [[package]]
 name = "rustls-webpki"
-version = "0.103.15"
+version = "0.103.16"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2"
+checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281"
 dependencies = [
  "ring",
  "rustls-pki-types",
diff --git a/src/tls.rs b/src/tls.rs
index e8da76f..5c48e2d 100644
--- a/src/tls.rs
+++ b/src/tls.rs
@@ -81,6 +81,10 @@ fn read_head<S: Read>(s: &mut S) -> Option<Vec<u8>> {
         }
         buf.extend_from_slice(&chunk[..n]);
         if let Some(i) = buf.windows(4).position(|w| w == b"\r\n\r\n") {
+            // Bound the complete wire head, not body bytes read in the same chunk.
+            if i + 4 > MAX_HEAD {
+                return None;
+            }
             buf.truncate(i + 2);
             return Some(buf);
         }
@@ -216,6 +220,45 @@ mod tests {
         }
     }
 
+    #[test]
+    fn head_size_limit_includes_terminator() {
+        for size in [MAX_HEAD - 1, MAX_HEAD, MAX_HEAD + 1, MAX_HEAD + 2048] {
+            let mut head = b"GET /health HTTP/1.1\r\nX-Pad: ".to_vec();
+            head.resize(size - 4, b'a');
+            head.extend_from_slice(b"\r\n\r\n");
+            let result = read_head(&mut std::io::Cursor::new(&head));
+            if size <= MAX_HEAD {
+                assert_eq!(result.as_deref(), Some(&head[..size - 2]), "size {size}");
+            } else {
+                assert!(result.is_none(), "accepted oversized head: {size}");
+            }
+        }
+    }
+
+    #[test]
+    fn head_size_limit_ignores_trailing_body() {
+        struct Chunked<'a>(&'a [u8]);
+        impl Read for Chunked<'_> {
+            fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
+                let limit = buf.len().min(1000);
+                self.0.read(&mut buf[..limit])
+            }
+        }
+        let mut input = b"GET /health HTTP/1.1\r\nX-Pad: ".to_vec();
+        input.resize(MAX_HEAD - 104, b'a');
+        input.extend_from_slice(b"\r\n\r\n");
+        let head_end = input.len();
+        input.extend_from_slice(&[b'b'; 4096]);
+        // The last read crosses MAX_HEAD, but the terminator precedes that limit.
+        let result = read_head(&mut Chunked(&input));
+        assert_eq!(result.as_deref(), Some(&input[..head_end - 2]));
+    }
+
+    #[test]
+    fn head_size_limit_rejects_unterminated_input() {
+        assert!(read_head(&mut std::io::Cursor::new(vec![b'a'; MAX_HEAD + 1])).is_none());
+    }
+
     #[test]
     fn head_parsing() {
         let h = b"GET /x?y=1 HTTP/1.1\r\nHost: a\r\nauthorization:  Bearer t \r\n";