mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-28 20:21:50 +01:00
The pre-READY readiness gate scanned for newlines incrementally, but the blank-line branch was not incremental. Each leading blank line reset the search to offset zero and copied the remaining buffer, so one untrusted chunk of blank lines plus one invalid line drove quadratic CPU work in the pre-authentication gate. Keep an advancing line-start cursor and a scan cursor over an append-only buffer. Skip a blank line by moving the cursors past the newline, without a buffer copy and without a search restart. Slice only the single candidate line for the decode. Each code unit is read at most one time. The scan counter now records the real indexOf distance, so a test can prove the blank-line path stays linear. Add a regression that sends one chunk of 15000 blank lines and an invalid line, and asserts the scan work is within 4x the bytes received and the contaminated fallback and cleanup happen. Co-authored-by: Paperclip <noreply@paperclip.ing>