gchq/CyberChef · error · OperationError

End of input reached before end of script

Error message

End of input reached before end of script

What it means

The PHP deserialization parser's read() function shifts characters one-by-one from the input array. When shift() returns undefined before the requested length is consumed, the serialized string is truncated — the format declares more data than is present.

Source

Thrown at src/core/operations/PHPDeserialize.mjs:57

     * @returns {string}
     */
    run(input, args) {
        /**
         * Recursive method for deserializing.
         * @returns {*}
         */
        function handleInput() {
            /**
             * Read `length` characters from the input, shifting them out the input.
             * @param length
             * @returns {string}
             */
            function read(length) {
                let result = "";
                for (let idx = 0; idx < length; idx++) {
                    const char = inputPart.shift();
                    if (char === undefined) {
                        throw new OperationError("End of input reached before end of script");
                    }
                    result += char;
                }
                return result;
            }

            /**
             * Read characters from the input until `until` is found.
             * @param until
             * @returns {string}
             */
            function readUntil(until) {
                let result = "";
                for (;;) {
                    const char = read(1);
                    if (char === until) {
                        break;
                    } else {

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Provide the complete, untruncated serialized string
  2. Check that string length markers (e.g., s:N:"...") match the actual byte length of the content, accounting for multibyte characters
  3. If the data came from a database or API, verify it was not truncated during extraction
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check: rough structural validation of PHP serialized data
function looksLikePhpSerialized(s) {
  return /^[nidbas]:/.test(s.trim());
}
if (!looksLikePhpSerialized(input)) {
  throw new Error("Input does not start with a valid PHP serialization type marker.");
}

Try / catch

try {
  const result = chef.phpDeserialize(input, [true]);
} catch (e) {
  if (/End of input/i.test(e.message)) {
    console.error("Serialized data is truncated — provide the complete string");
  } else { throw e; }
}

Prevention

When it happens

Trigger: A serialized string's length marker exceeds the available content (e.g., s:5:"ab"; claims 5 bytes but only 2 remain). An array declaration says a:3:{...} but the input ends before all key/value pairs are read. Any truncation mid-element due to copy-paste or encoding conversion that altered byte counts.

Common situations: Copy-pasting a serialized string and accidentally cutting it short. Encoding conversion (UTF-8 to Latin1) that changes multibyte character counts so the byte-length markers no longer match. Database extraction that truncated a serialized BLOB.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/570f6fbd5da4f278. Report an issue: GitHub.