{"record":{"id":"c30fe9356f0c77fc","repo":"nodejs/node","slug":"invalid-base64-encoded-comment-n","errorCode":null,"errorMessage":"invalid base64-encoded comment\\n","messagePattern":"invalid base64-encoded comment\\\\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"deps/brotli/c/tools/brotli.c","lineNumber":488,"sourceCode":"                               BROTLI_MAX_WINDOW_BITS, &params->lgwin);\n          if (!lgwin_set) {\n            fprintf(stderr, \"error parsing lgwin value [%s]\\n\", argv[i]);\n            return COMMAND_INVALID;\n          }\n          if (params->lgwin != 0 && params->lgwin < BROTLI_MIN_WINDOW_BITS) {\n            fprintf(stderr,\n                    \"lgwin parameter (%d) smaller than the minimum (%d)\\n\",\n                    params->lgwin, BROTLI_MIN_WINDOW_BITS);\n            return COMMAND_INVALID;\n          }\n        } else if (c == 'C') {\n          if (comment_set) {\n            fprintf(stderr, \"comment already set\\n\");\n            return COMMAND_INVALID;\n          }\n          params->comment_len = MAX_COMMENT_LEN;\n          if (!ParseBase64(argv[i], params->comment, &params->comment_len)) {\n            fprintf(stderr, \"invalid base64-encoded comment\\n\");\n            return COMMAND_INVALID;\n          }\n          comment_set = BROTLI_TRUE;\n        } else if (c == 'D') {\n          if (params->dictionary_path) {\n            fprintf(stderr, \"dictionary path already set\\n\");\n            return COMMAND_INVALID;\n          }\n          params->dictionary_path = argv[i];\n        } else if (c == 'S') {\n          if (suffix_set) {\n            fprintf(stderr, \"suffix already set\\n\");\n            return COMMAND_INVALID;\n          }\n          suffix_set = BROTLI_TRUE;\n          params->suffix = argv[i];\n        }\n      }","sourceCodeStart":470,"sourceCodeEnd":506,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/brotli/c/tools/brotli.c#L470-L506","documentation":"`ParseBase64` (brotli.c:182) decodes a relaxed base64 comment: it allows `+`/`-` and `/`/`_`, skips whitespace, requires padding count ≤ 2, and rejects decoded output longer than `MAX_COMMENT_LEN` (80 bytes). Any violation prints `invalid base64-encoded comment` and aborts. The comment is binary metadata embedded in the stream header.","triggerScenarios":"`brotli -C '!@#' in` (illegal char), `brotli -C '===' in` (padding >2), `brotli -C \"$(head -c 200 /dev/urandom | base64)\" in` (decoded > 80 bytes), `brotli -C 'A' in` (invalid length/padding combination yields false).","commonSituations":"Passing raw text instead of base64; URL-safe vs standard base64 mismatch handled (both are accepted here, so the issue is usually length or stray chars); very long metadata.","solutions":["Encode with standard base64 and keep decoded length ≤ 80 bytes: `brotli -C \"$(printf %s \"$c\" | base64)\" in`.","Strip non-base64 characters and verify padding (0–2 `=`).","If the comment is binary, ensure the base64 string decodes to ≤ 80 bytes."],"exampleFix":"# before\nbrotli -C 'hello world' in\n# after\nbrotli -C \"$(printf %s 'hello world' | base64)\" in","handlingStrategy":"validation","validationCode":"# bash: pre-validate the comment as base64 decoding to <=80 bytes\nvalidate_b64() {\n  python3 - \"$1\" <<'PY'\nimport sys, base64, binascii\ns=''.join(sys.argv[1].split())\ntry:\n    raw=base64.b64decode(s+'='*((4-len(s)%4)%4))\nexcept binascii.Error:\n    sys.exit('bad base64')\nif len(raw)>80: sys.exit('decoded >80 bytes')\nPY\n}\nargv=(\"$@\")\nfor ((i=0;i<${#argv[@]};i++)); do\n  if [ \"${argv[$i]}\" = -C ]; then\n    validate_b64 \"${argv[$((i+1))]:-}\" || exit 2\n  fi\ndone\nbrotli \"$@\"","typeGuard":null,"tryCatchPattern":"# bash\nif ! brotli \"$@\"; then rc=$?; echo \"brotli exit $rc; verify base64 comment\" >&2; exit \"$rc\"; fi","preventionTips":["Always base64-encode comment bytes; never pass raw text to `-C`.","Keep decoded comment length <= 80 bytes (MAX_COMMENT_LEN).","Use standard or URL-safe base64 (both `+/-` and `/_` are accepted)."],"tags":["cli","brotli","argument-parsing","comment","base64"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}