{"record":{"id":"dd8f562111a72fd6","repo":"router-for-me/CLIProxyAPI","slug":"open-zip-w","errorCode":null,"errorMessage":"open zip: %w","messagePattern":"open zip: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/pluginstore/install.go","lineNumber":256,"sourceCode":"\t\treturn plugin, nil\n\t}\n\treturn Plugin{}, fmt.Errorf(\"direct install plugin %q version %q not found in source\", id, version)\n}\n\nfunc InstallArchive(archiveData []byte, plugin Plugin, options InstallOptions) (InstallResult, error) {\n\toptions = normalizeInstallOptions(options)\n\tid := strings.TrimSpace(plugin.ID)\n\tif !validPluginID(id) {\n\t\treturn InstallResult{}, fmt.Errorf(\"invalid plugin id %q\", plugin.ID)\n\t}\n\tversion := normalizeVersion(plugin.Version)\n\tif !validPluginVersion(version) {\n\t\treturn InstallResult{}, fmt.Errorf(\"invalid plugin version %q\", plugin.Version)\n\t}\n\tplugin.Version = version\n\treader, errZip := zip.NewReader(bytes.NewReader(archiveData), int64(len(archiveData)))\n\tif errZip != nil {\n\t\treturn InstallResult{}, fmt.Errorf(\"open zip: %w\", errZip)\n\t}\n\n\tlibraryData, mode, errLibrary := readTargetLibrary(reader, id, version, options.GOOS)\n\tif errLibrary != nil {\n\t\treturn InstallResult{}, errLibrary\n\t}\n\n\ttargetPath, errTarget := installTargetPath(options, id, version)\n\tif errTarget != nil {\n\t\treturn InstallResult{}, errTarget\n\t}\n\toverwritten := false\n\tif _, errStat := os.Stat(targetPath); errStat == nil {\n\t\toverwritten = true\n\t} else if !errors.Is(errStat, os.ErrNotExist) {\n\t\treturn InstallResult{}, fmt.Errorf(\"stat target plugin: %w\", errStat)\n\t}\n\tif overwritten {","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/pluginstore/install.go#L238-L274","documentation":"Wrapped error from InstallArchive when zip.NewReader fails on the provided archiveData, meaning the bytes are not a valid ZIP archive (bad magic, truncated file, corruption). The library opens the archive fully in memory (bytes.NewReader over the whole slice) before extracting the plugin library, so any parse failure aborts before touching the filesystem.","triggerScenarios":"Passing bytes that are not a ZIP: a tarball (.tar.gz), a raw .so/.dylib file, an HTML error page saved as the 'artifact', a truncated download, or a corrupted buffer.","commonSituations":"Download pipeline that forgot to decompress/repackage, or fetched the wrong content type; disk-full corruption of a cached artifact; double-gzip; upstream serving a redirect body instead of following it; checksum verification skipped so corruption went unnoticed earlier.","solutions":["Verify the bytes are a ZIP before calling: check the 'PK\\x03\\x04' magic or open with archive/zip yourself","Confirm the download actually retrieved the artifact (HTTP status, Content-Type, length) and wasn't an error page","If corruption is possible in transit/storage, run checksum verification before install"],"exampleFix":"// before\ndata, _ := os.ReadFile(\"plugin.tar.gz\") // wrong format\nres, err := pluginstore.InstallArchive(data, plugin, options)\n\n// after\ndata, err := os.ReadFile(\"plugin.zip\")\nif err != nil { return err }\nif _, err := zip.NewReader(bytes.NewReader(data), int64(len(data))); err != nil {\n    return fmt.Errorf(\"not a valid zip archive: %w\", err)\n}\nres, err := pluginstore.InstallArchive(data, plugin, options)","handlingStrategy":"validation","validationCode":"func isZip(data []byte) bool {\n    return len(data) > 4 && string(data[:4]) == \"PK\\x03\\x04\"\n}\n\nfunc preflightArchive(data []byte) error {\n    if !isZip(data) {\n        return errors.New(\"artifact is not a zip archive\")\n    }\n    if _, err := zip.NewReader(bytes.NewReader(data), int64(len(data))); err != nil {\n        return fmt.Errorf(\"zip parse failed: %w\", err)\n    }\n    return nil\n}","typeGuard":"func isZipOpenError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"open zip:\")\n}","tryCatchPattern":"if _, err := pluginstore.InstallArchive(data, plugin, options); err != nil {\n    if isZipOpenError(err) {\n        var formatErr zip.FormatError\n        if errors.As(err, &formatErr) {\n            return errors.New(\"corrupt or non-zip artifact; re-download and verify checksum\")\n        }\n    }\n}","preventionTips":["Always verify checksums on downloaded artifacts before install","Check HTTP status and Content-Type when fetching artifacts to catch error pages","Preflight the zip magic bytes in your download pipeline"],"tags":["go","plugin-store","zip","archive","validation"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}