{"record":{"id":"0c33e9012264c6d8","repo":"golang/go","slug":"readzip-encoded-file-exceeds-allowed-size","errorCode":null,"errorMessage":"ReadZip: encoded file exceeds allowed size","messagePattern":"ReadZip: encoded file exceeds allowed size","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modfetch/codehost/vcs.go","lineNumber":628,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tunlock, err := r.mu.Lock()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer unlock()\n\n\tf, err := os.CreateTemp(\"\", \"go-readzip-*.zip\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif r.cmd.doReadZip != nil {\n\t\tlw := &limitedWriter{\n\t\t\tW:               f,\n\t\t\tN:               maxSize,\n\t\t\tErrLimitReached: errors.New(\"ReadZip: encoded file exceeds allowed size\"),\n\t\t}\n\t\terr = r.cmd.doReadZip(ctx, lw, r.dir, rev, subdir, r.remote)\n\t\tif err == nil {\n\t\t\t_, err = f.Seek(0, io.SeekStart)\n\t\t}\n\t} else if r.cmd.vcs == \"fossil\" {\n\t\t// If you run\n\t\t//\tfossil zip -R .fossil --name prefix trunk /tmp/x.zip\n\t\t// fossil fails with \"unable to create directory /tmp\" [sic].\n\t\t// Change the command to run in /tmp instead,\n\t\t// replacing the -R argument with an absolute path.\n\t\targs := r.cmd.readZip(rev, subdir, r.remote, filepath.Base(f.Name()))\n\t\tfor i := range args {\n\t\t\tif args[i] == \".fossil\" {\n\t\t\t\targs[i] = filepath.Join(r.dir, \".fossil\")\n\t\t\t}\n\t\t}\n\t\t_, err = Run(ctx, filepath.Dir(f.Name()), args)","sourceCodeStart":610,"sourceCodeEnd":646,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modfetch/codehost/vcs.go#L610-L646","documentation":"ReadZip funnels the VCS-produced archive (git/hg archive) through a limitedWriter capped at the caller-supplied maxSize, which ultimately derives from codehost.MaxZipFile (500 MiB). If the encoded zip would exceed the cap, the writer short-writes and returns this error, aborting the read.","triggerScenarios":"A module's zip representation produced by the VCS for the requested revision/subdir exceeds the maxSize limit passed to ReadZip.","commonSituations":"Very large repositories fetched as a module; requesting a wide revision range or no subdir so the whole repo is archived; vendored large binaries or generated files inside the repo; a heavy subdirectory selected as subdir.","solutions":["Narrow the module: pick a subdir, split the module, or remove large generated/binary files from the repository.","Pin to a smaller revision or tag that predates the bulk that pushed it over the limit.","If you control the toolchain, raise codehost.MaxZipFile and rebuild go; otherwise request the upstream maintainer trim the repo."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep modules small; split monorepos into multiple modules by subtree.","Avoid checking large generated artifacts or binaries into a module's repo."],"tags":["go","modules","vcs","size-limit"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}