nodejs/node · error

corrupt input [%s]\n

Error message

corrupt input [%s]\n

What it means

Printed by the brotli CLI decompressor (DecompressFile at brotli.c:1232) when the stream's metadata comment fails validation. The OnMetadataStart/OnMetadataChunk callbacks set comment_state to COMMENT_BAD during decoding. Brotli streams can carry an optional comment/metadata section; if the declared comment length does not match what actually arrives, the decoder flags the input as corrupt. The function returns BROTLI_FALSE, aborting decompression.

Source

Thrown at deps/brotli/c/tools/brotli.c:1232

  return BROTLI_TRUE;
}

static BROTLI_BOOL DecompressFile(Context* context) {
  BrotliDecoderState* s = context->decoder;
  BrotliDecoderResult result = BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT;
  if (context->comment_len) {
    context->comment_state = COMMENT_INIT;
    BrotliDecoderSetMetadataCallbacks(s, &OnMetadataStart, &OnMetadataChunk,
        (void*)context);
  } else {
    context->comment_state = COMMENT_OK;
  }

  InitializeBuffers(context);
  for (;;) {
    /* Early check */
    if (context->comment_state == COMMENT_BAD) {
      fprintf(stderr, "corrupt input [%s]\n",
              PrintablePath(context->current_input_path));
      if (context->verbosity > 0) {
        fprintf(stderr, "reason: comment mismatch\n");
      }
      return BROTLI_FALSE;
    }
    if (result == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT) {
      if (!HasMoreInput(context)) {
        fprintf(stderr, "corrupt input [%s]\n",
                PrintablePath(context->current_input_path));
        if (context->verbosity > 0) {
          fprintf(stderr, "reason: truncated input\n");
        }
        return BROTLI_FALSE;
      }
      if (!ProvideInput(context)) return BROTLI_FALSE;
    } else if (result == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) {
      if (!ProvideOutput(context)) return BROTLI_FALSE;

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Re-download or re-transfer the .br file in binary mode and retry decompression.
  2. Re-compress the original source with a known-good brotli encoder to regenerate a valid stream.
  3. Run with the -v flag to see the 'reason: comment mismatch' confirmation and verify the issue is metadata, not the compressed payload itself.
  4. If you control the encoder, verify that the comment length written to the stream header exactly matches the bytes emitted through the metadata callbacks.

Example fix

// before: writing a stream with mismatched comment metadata
BrotliEncoderSetMetadataCallback(encoder, write_meta, ctx);
// encoder declares comment_len=N but fewer bytes are sent

// after: ensure the declared length matches emitted bytes
context->comment_len = actual_metadata_byte_count;
BrotliDecoderSetMetadataCallbacks(s, &OnMetadataStart, &OnMetadataChunk, ctx);
Defensive patterns

Strategy: validation

Validate before calling

// Before decompressing, verify the .br file is not truncated or corrupt
#include <sys/stat.h>
struct stat st;
if (stat(filepath, &st) != 0 || st.st_size == 0) {
    fprintf(stderr, "file missing or empty: %s\n", filepath);
    return -1;
}
// Optionally verify a known checksum
// sha256sum expected vs actual

Try / catch

// C has no exceptions; check the return value of DecompressFile
BROTLI_BOOL ok = DecompressFile(context);
if (!ok) {
    // context already printed 'corrupt input' to stderr
    // handle: report file as corrupt, skip or re-acquire
    return EXIT_FAILURE;
}

Prevention

When it happens

Trigger: Decompressing a .br file whose metadata comment block was truncated, corrupted, or whose comment_len field disagrees with the actual metadata bytes received via the OnMetadataChunk callback. Triggered during the main decode loop's early-check at the top of each iteration when comment_state has been set to COMMENT_BAD by a prior callback invocation.

Common situations: A .br file was partially downloaded or transferred in text mode (line-ending conversion corrupting binary). A custom encoder wrote an incorrect comment_len header. The file was damaged on disk or truncated by a network proxy.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/ad317f2816015d5c. Report an issue: GitHub.