{"record":{"id":"431331fbd66d423b","repo":"inancgumus/learngo","slug":"file-size-len-buf-431331","errorCode":null,"errorMessage":"file size < len(buf)","messagePattern":"file size < len\\(buf\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"advfuncs/08-png-detector/main.go","lineNumber":67,"sourceCode":"func read(filename string, buf []byte) error {\n\tfile, err := os.Open(filename)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer file.Close()\n\n\tfi, err := file.Stat()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif fi.Size() <= int64(len(buf)) {\n\t\treturn fmt.Errorf(\"file size < len(buf)\")\n\t}\n\n\t_, err = io.ReadFull(file, buf)\n\treturn err\n}","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/inancgumus/learngo/blob/3c475a78e54336c6255e925ff66b8ef4da6a2ae7/advfuncs/08-png-detector/main.go#L49-L85","documentation":"read() fires this error when file.Stat() reports a size less than or equal to len(buf), meaning the file is too short (or empty) to hold the magic-number buffer being checked (e.g. PNG header). The detector treats the file as not matching the format. It is a pre-flight size check before io.ReadFull.","triggerScenarios":"Thrown at advfuncs/08-png-detector/main.go:67 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Classify the file as invalid format and continue with the next file.","Report the short file to the user with its name and actual size.","Use io.ReadFull's ErrUnexpectedEOF instead of the custom check to signal truncation."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3c475a78e54336c6255e925ff66b8ef4da6a2ae7","analyzedAt":"2026-09-02T10:14:38.492Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}