{"record":{"id":"066b289f15ed77a2","repo":"containerd/containerd","slug":"failed-encoding-size-v","errorCode":null,"errorMessage":"failed encoding size = %v","messagePattern":"failed encoding size = (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/snapshots/storage/bolt.go","lineNumber":615,"sourceCode":"\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif err := bkt.Put(v.key, e); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc encodeSize(size int64) ([]byte, error) {\n\tvar (\n\t\tbuf         [binary.MaxVarintLen64]byte\n\t\tsizeEncoded = buf[:]\n\t)\n\tsizeEncoded = sizeEncoded[:binary.PutVarint(sizeEncoded, size)]\n\n\tif len(sizeEncoded) == 0 {\n\t\treturn nil, fmt.Errorf(\"failed encoding size = %v\", size)\n\t}\n\treturn sizeEncoded, nil\n}\n\nfunc encodeID(id uint64) ([]byte, error) {\n\tvar (\n\t\tbuf       [binary.MaxVarintLen64]byte\n\t\tidEncoded = buf[:]\n\t)\n\tidEncoded = idEncoded[:binary.PutUvarint(idEncoded, id)]\n\n\tif len(idEncoded) == 0 {\n\t\treturn nil, fmt.Errorf(\"failed encoding id = %v\", id)\n\t}\n\treturn idEncoded, nil\n}\n\nfunc adaptSnapshot(info snapshots.Info) filters.Adaptor {","sourceCodeStart":597,"sourceCodeEnd":633,"githubUrl":"https://github.com/containerd/containerd/blob/4246446a2bf7d03837b0244118d858799393bd80/core/snapshots/storage/bolt.go#L597-L633","documentation":"encodeSize in the bolt snapshotter metastore encodes an int64 size as a varint. It errors only if the encoded byte slice is empty after binary.PutVarint, which in practice never happens for any int64 value — the guard is defensive. If seen, it indicates a corrupted or misused metastore code path.","triggerScenarios":"putUsage calls encodeSize with a size value when storing snapshot usage; the error fires if binary.PutVarint returns 0 bytes written, which cannot occur with binary.MaxVarintLen64 capacity for valid int64 input.","commonSituations":"Essentially unreachable in practice; would only appear if the bolt snapshotter metastore code was modified or if instrumentation/wrapping changed PutVarint behavior.","solutions":["Report/inspect the size value being passed to putUsage; a non-int64 (e.g. float cast) caller bug is the only plausible cause","Update containerd to a current patch release to rule out an old defect","Rebuild/inspect the bolt database file (containerd metadata snapshot bolt db) for corruption"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if size < math.MinInt64 || size > math.MaxInt64 {\n    return fmt.Errorf(\"size out of int64 range: %v\", size)\n}","typeGuard":null,"tryCatchPattern":"encoded, err := encodeSize(size)\nif err != nil {\n    log.WithError(err).Errorf(\"snapshot usage size encoding failed for size=%d\", size)\n    return err\n}","preventionTips":["Pass only int64 values into putUsage","Treat this as a code-level bug and report it upstream rather than working around it"],"tags":["storage","snapshotter","encoding"],"backgroundTag":"varint-encode-failed","analyzedSha":"4246446a2bf7d03837b0244118d858799393bd80","analyzedAt":"2026-09-02T00:14:43.053Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}