{"record":{"id":"b7804829415595e6","repo":"slimtoolkit/slim","slug":"dockerfile-line-greater-than-max-allowed-size-of","errorCode":null,"errorMessage":"dockerfile line greater than max allowed size of %d","messagePattern":"dockerfile line greater than max allowed size of (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/docker/dockerfile/ast/parser.go","lineNumber":396,"sourceCode":"\t\tline = d.lineContinuationRegex.ReplaceAllString(line, \"\")\n\t\treturn line, false\n\t}\n\treturn line, true\n}\n\n// TODO: remove stripLeftWhitespace after deprecation period. It seems silly\n// to preserve whitespace on continuation lines. Why is that done?\nfunc processLine(d *Directive, token []byte, stripLeftWhitespace bool) ([]byte, error) {\n\tif stripLeftWhitespace {\n\t\ttoken = trimWhitespace(token)\n\t}\n\treturn trimComments(token), d.possibleParserDirective(string(token))\n}\n\nfunc handleScannerError(err error) error {\n\tswitch err {\n\tcase bufio.ErrTooLong:\n\t\treturn errors.Errorf(\"dockerfile line greater than max allowed size of %d\", bufio.MaxScanTokenSize-1)\n\tdefault:\n\t\treturn err\n\t}\n}\n","sourceCodeStart":378,"sourceCodeEnd":401,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/docker/dockerfile/ast/parser.go#L378-L401","documentation":"When the Dockerfile parser's bufio.Scanner exceeds bufio.MaxScanTokenSize, handleScannerError converts bufio.ErrTooLong into this descriptive error reporting the actual max line size (MaxScanTokenSize-1). It means a single line in the Dockerfile is too long for the scanner to tokenize.","triggerScenarios":"Calling Parse on a Dockerfile that contains one line longer than 64KB (bufio.MaxScanTokenSize-1 = 65535 bytes), e.g. a huge RUN command or a minified payload embedded on one line.","commonSituations":"Machine-generated Dockerfiles with base64 blobs or curl one-liners piped into sh, minified assets copied inline, or CI scripts concatenating many commands onto one RUN line.","solutions":["Split the long RUN line into multiple RUN statements or use a heredic/multiline form (RUN <<EOF).","Move large payloads out of the Dockerfile — use COPY of a file instead of inline content.","Read large blobs from a build context file or remote URL at build time rather than embedding them on one line.","Pre-process the Dockerfile to wrap long lines with backslash continuations before parsing."],"exampleFix":"// before (Dockerfile)\nRUN echo \"<64KB+ base64 blob>\" > /app/payload\n// after (Dockerfile)\nCOPY payload.b64 /tmp/payload.b64\nRUN base64 -d /tmp/payload.b64 > /app/payload && rm /tmp/payload.b64","handlingStrategy":"validation","validationCode":"func checkDockerfileLineLength(path string, max int) error {\n    f, err := os.Open(path)\n    if err != nil { return err }\n    defer f.Close()\n    sc := bufio.NewScanner(f)\n    for line := 1; sc.Scan(); line++ {\n        if len(sc.Bytes()) > max {\n            return fmt.Errorf(\"line %d exceeds %d bytes\", line, max)\n        }\n    }\n    return sc.Err()\n}\n// call with max = bufio.MaxScanTokenSize-1 before Parse","typeGuard":null,"tryCatchPattern":"layers, err := parser.Parse(ctx, dockerfile)\nif err != nil {\n    if strings.Contains(err.Error(), \"dockerfile line greater than max allowed size\") {\n        return fmt.Errorf(\"Dockerfile has an over-long line; split RUN commands or COPY payloads: %w\", err)\n    }\n    return err\n}","preventionTips":["Lint Dockerfiles in CI to enforce a per-line length limit.","Prefer COPY of files over inline echo/base64 blobs in RUN lines.","Use multiline continuation or heredocs for long build commands."],"tags":["dockerfile","parser","bufio","input-size"],"backgroundTag":"dockerfile-line-too-long","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}