Skip to content
Astera Technology

Quarantine candidate files that exceed supplied parse limits

One large malformed output exhausts the evaluator instead of yielding a controlled disposition.

Download complete case notes and answer keys ↓

Define the local evaluation task

A synthetic evaluator intake allows at most 100 UTF-8 bytes and at most three LF-separated nonempty rows. Check bytes before inspecting row count, preserving the raw text on hold. Exactly 100 bytes is within the size bound. Empty text yields zero rows. These are local resource bounds, not security or file-format certification.

  1. Count bytes in the declared encoding
  2. Check nonempty LF rows only within the byte bound
  3. Hold over-limit text before parsing

A held input keeps its raw text and reason; do not silently trim it to fit.

Use the filled cases

Original synthetic input and literal answer key
CaseSupplied inputExpected structured outputDecision and reason
Exact byte limit{"raw":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}{"status":"ready-to-parse","bytes":100,"rows":1}Exactly 100 ASCII bytes fit; ready-to-parse still is not a parsed-content pass.
One byte over limit{"raw":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}{"status":"size-hold","bytes":101}Size stops intake before a row-count or parser decision.
Four nonempty rows{"raw":"a\nb\nc\nd"}{"status":"row-hold","bytes":7,"rows":4}Seven bytes fit but four rows exceed the separate row bound.
Download editable CSV ↓

Work the four-rows case. Which output is required, and why?

Show the worked answer

{"status":"row-hold","bytes":7,"rows":4} — Seven bytes fit but four rows exceed the separate row bound.

Run the self-contained evaluator

Save as .mjs and run with Node.js; supplied fixtures only
import assert from 'node:assert/strict';
import {Buffer} from 'node:buffer';

function evaluate(x){
 const bytes=Buffer.byteLength(x.raw,'utf8');if(bytes>100)return {status:'size-hold',bytes};const rows=x.raw===''?0:x.raw.split('\n').filter(line=>line!=='').length;
 return {status:rows>3?'row-hold':'ready-to-parse',bytes,rows};
}

const cases = [
  {
    "id": "exact-byte-limit",
    "input": {
      "raw": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    },
    "expected": {
      "status": "ready-to-parse",
      "bytes": 100,
      "rows": 1
    }
  },
  {
    "id": "one-byte-over",
    "input": {
      "raw": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    },
    "expected": {
      "status": "size-hold",
      "bytes": 101
    }
  },
  {
    "id": "four-rows",
    "input": {
      "raw": "a\nb\nc\nd"
    },
    "expected": {
      "status": "row-hold",
      "bytes": 7,
      "rows": 4
    }
  }
];
for (const c of cases) assert.deepEqual(evaluate(c.input), c.expected, c.id);
console.log(JSON.stringify({checked:cases.length,caseIds:cases.map(c=>c.id)}));
Download runnable example ↓

Use a separate parser and business validator after these local bounds. Limits must be supplied for a deployment; this example does not establish safe handling of arbitrary files.

Related resources

Development services →