{"record":{"id":"d179583ba4339daf","repo":"goharbor/harbor","slug":"request-entity-too-large","errorCode":"REQUEST_ENTITY_TOO_LARGE","errorMessage":"The file is too large to be processed","messagePattern":"The file is too large to be processed","errorType":"error_code","errorClass":"lib/errors.Error","httpStatus":413,"severity":"error","filePath":"src/controller/artifact/processor/cnai/parser/base.go","lineNumber":32,"sourceCode":"\npackage parser // nolint:revive\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"io\"\n\t\"path/filepath\"\n\n\tocispec \"github.com/opencontainers/image-spec/specs-go/v1\"\n\n\t\"github.com/goharbor/harbor/src/lib/errors\"\n\t\"github.com/goharbor/harbor/src/pkg/artifact\"\n\t\"github.com/goharbor/harbor/src/pkg/registry\"\n)\n\nvar (\n\t// errFileTooLarge is returned when the file is too large to be processed.\n\terrFileTooLarge = errors.New(\"The file is too large to be processed\")\n)\n\nconst (\n\t// contentTypeTextPlain is the content type of text/plain.\n\tcontentTypeTextPlain = \"text/plain; charset=utf-8\"\n\t// contentTypeTextMarkdown is the content type of text/markdown.\n\tcontentTypeMarkdown = \"text/markdown; charset=utf-8\"\n\t// contentTypeJSON is the content type of application/json.\n\tcontentTypeJSON = \"application/json; charset=utf-8\"\n\n\t// defaultFileSizeLimit is the default file size limit.\n\tdefaultFileSizeLimit = 1024 * 1024 * 4 // 4MB\n\n\t// formatTar is the format of tar file.\n\tformatTar = \".tar\"\n\t// formatRaw is the format of raw file.\n\tformatRaw = \".raw\"\n)","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/goharbor/harbor/blob/7b2fd08cc568955cca339afeefab27372840d936/src/controller/artifact/processor/cnai/parser/base.go#L14-L50","documentation":"The base parser for CNAI (Harbor's AI artifact type) refuses to materialize addition layers larger than defaultFileSizeLimit (4MB), returning an error mapped to HTTP 413 Request Entity Too Large. There are two checks: a cheap pre-check on the manifest-declared layer.Size, and a second check on the actual bytes materialized when pulling/untarring the layer, so decompression or sparse-tar bombs that expand past 4MB are also rejected.","triggerScenarios":"Requesting the readme/license/files addition on a CNAI artifact whose relevant layer (media type with .tar or .raw extension) is declared larger than 4MB, or whose content expands beyond 4MB when decoded (readAllLimited / untar).","commonSituations":"AI model artifacts packaging multi-megabyte model cards or README files, gzipped layers that decompress well past their blob size, sparse tar members inside the layer.","solutions":["Keep each readme/license/files layer under 4MB — trim or split the content and push a new version","Prefer the .raw layer format for large text and reference external storage for big assets","For .tar layers, exclude huge or sparse members when packaging the artifact","The 4MB limit is a code constant (defaultFileSizeLimit), not a runtime setting — if it must change, rebuild harbor-core"],"exampleFix":"# before: README layer is 12MB -> 413 on additions request\n# after: trim the file and push the smaller layer\ntruncate -s 3M model-card.md   # keep layer and its tar-expanded size <= 4MB","handlingStrategy":"validation","validationCode":"// producer-side, before pushing a CNAI addition layer\nconst maxAdditionLayerSize = 4 * 1024 * 1024 // mirrors defaultFileSizeLimit\nif layer.Size > maxAdditionLayerSize {\n    return fmt.Errorf(\"layer %s is %d bytes; additions layers must stay under 4MB (declared AND expanded)\", layer.Digest, layer.Size)\n}","typeGuard":null,"tryCatchPattern":"if err := parser.Parse(ctx, art, layer); err != nil {\n    var tooLarge *errors.Error\n    if errors.As(err, &tooLarge) && tooLarge.Code == errors.RequestEntityTooLargeCode {\n        // repack the layer smaller; retrying the same blob will fail identically\n    }\n}","preventionTips":["Keep readme/license/files payloads small; link large docs instead of embedding","Check both the compressed blob size and the uncompressed/tar-expanded size","Remember the 4MB limit is hardcoded — design content around it"],"tags":["go","harbor","cnai","artifact","size-limit","http-413"],"backgroundTag":null,"analyzedSha":"7b2fd08cc568955cca339afeefab27372840d936","analyzedAt":"2026-08-16T00:00:10.961Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}