{"record":{"id":"4724f5291153c3a5","repo":"yorukot/superfile","slug":"image-file-too-large-d-bytes","errorCode":null,"errorMessage":"image file too large: %d bytes","messagePattern":"image file too large: (.+?) bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pkg/file_preview/image_preview.go","lineNumber":147,"sourceCode":"\t)\n\tif err == nil {\n\t\t// Cache the successful result\n\t\tp.cache.Set(getPreviewObjKey(path, dimensions, RendererANSI), preview)\n\t}\n\treturn preview, \"\", err\n}\n\n// ImagePreviewWithRenderer generates an image preview using the specified renderer.\n// Returns (render, rawTransmit, error).\nfunc (p *ImagePreviewer) ImagePreviewWithRenderer(path string, maxWidth int, maxHeight int,\n\tdefaultBGColor string, renderer ImageRenderer, sideAreaWidth int) (string, string, error) {\n\tinfo, err := os.Stat(path)\n\tif err != nil {\n\t\treturn \"\", \"\", err\n\t}\n\tconst maxFileSize = 100 * 1024 * 1024 // 100MB limit\n\tif info.Size() > maxFileSize {\n\t\treturn \"\", \"\", fmt.Errorf(\"image file too large: %d bytes\", info.Size())\n\t}\n\n\tdata, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn \"\", \"\", err\n\t}\n\n\t// Use the new image preparation pipeline\n\timg, originalWidth, originalHeight, err := prepareImageForPreview(data)\n\tif err != nil {\n\t\treturn \"\", \"\", err\n\t}\n\n\tswitch renderer {\n\tcase RendererKitty:\n\t\tresult, err := p.renderWithKittyUsingTermCap(img, path, originalWidth,\n\t\t\toriginalHeight, maxWidth, maxHeight, sideAreaWidth)\n\t\tif err != nil {","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/pkg/file_preview/image_preview.go#L129-L165","documentation":"ImagePreviewWithRenderer stats the image file before reading and enforces a 100MB hard limit to prevent loading enormous files into memory. This error reports the actual file size in bytes when it exceeds maxFileSize (100*1024*1024). Reading and decoding such files is refused by design.","triggerScenarios":"Calling ImagePreview/ImagePreviewWithRenderer on an image whose os.Stat size is greater than 100MB (1073741824... exactly 104857600) bytes.","commonSituations":"Previewing large raw photos (e.g., uncompressed TIFFs, huge PNGs), scanned documents, or files in a downloads folder; accidentally pointing the previewer at a video or archive.","solutions":["Check os.Stat(path).Size() before calling and skip/show a placeholder for files > 100MB","Generate a downscaled thumbnail with an external tool for very large images","Filter the file listing to exclude files above a size threshold","If legitimately needed, raise the limit in a fork — but beware memory use"],"exampleFix":"// before\nout, raw, err := previewer.ImagePreview(largePath, w, h, bg, side)\n// after\nif info, err := os.Stat(largePath); err == nil && info.Size() > 100*1024*1024 {\n\treturn \"[image too large to preview]\", \"\", nil\n}\nout, raw, err := previewer.ImagePreview(largePath, w, h, bg, side)","handlingStrategy":"validation","validationCode":"info, err := os.Stat(path)\nif err == nil && info.Size() > 100*1024*1024 { return ErrTooLarge }","typeGuard":null,"tryCatchPattern":"out, raw, err := previewer.ImagePreviewWithRenderer(path, w, h, bg, side, r)\nif err != nil && strings.HasPrefix(err.Error(), \"image file too large\") {\n\treturn \"[image exceeds 100MB preview limit]\", \"\", nil\n}","preventionTips":["Pre-screen file sizes in the file listing and hide preview for >100MB","Generate thumbnails for large media instead of full previews","Handle os.Stat errors separately from the size check","Document the 100MB limit in user-facing help"],"tags":["go","image","filesystem","limits"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}