mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-03-30 13:43:26 +08:00
fix: clamp suggest-compact counter overflow, add 9 boundary tests
Counter file could contain huge values (e.g. 999999999999) that pass Number.isFinite() but cause unbounded growth. Added range clamp to reject values outside [1, 1000000]. New tests cover: - Counter overflow reset (huge number, negative number) - COMPACT_THRESHOLD zero fallback - session-end empty sections (no tools/files omits headers) - session-end slice boundaries (10 messages, 20 tools, 30 files) - post-edit-console-warn 5-match limit - post-edit-console-warn ignores console.warn/error/debug
This commit is contained in:
@@ -44,7 +44,11 @@ async function main() {
|
||||
const bytesRead = fs.readSync(fd, buf, 0, 64, 0);
|
||||
if (bytesRead > 0) {
|
||||
const parsed = parseInt(buf.toString('utf8', 0, bytesRead).trim(), 10);
|
||||
count = Number.isFinite(parsed) ? parsed + 1 : 1;
|
||||
// Clamp to reasonable range — corrupted files could contain huge values
|
||||
// that pass Number.isFinite() (e.g., parseInt('9'.repeat(30)) => 1e+29)
|
||||
count = (Number.isFinite(parsed) && parsed > 0 && parsed <= 1000000)
|
||||
? parsed + 1
|
||||
: 1;
|
||||
}
|
||||
// Truncate and write new value
|
||||
fs.ftruncateSync(fd, 0);
|
||||
|
||||
Reference in New Issue
Block a user