{"record":{"id":"9f70905dee453a99","repo":"nats-io/nats-server","slug":"not-enough-overwrite-bytes-read-d-d","errorCode":null,"errorMessage":"not enough overwrite bytes read (%d != %d)","messagePattern":"not enough overwrite bytes read \\((.+?) != (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/filestore.go","lineNumber":6777,"sourceCode":"\t}\n}\n\n// Lock should be held.\nfunc (mb *msgBlock) eraseMsg(seq uint64, ri, rl int, isLastBlock bool) error {\n\tvar le = binary.LittleEndian\n\tvar hdr [msgHdrSize]byte\n\n\tle.PutUint32(hdr[0:], uint32(rl))\n\tle.PutUint64(hdr[4:], seq|ebit)\n\tle.PutUint64(hdr[12:], 0)\n\tle.PutUint16(hdr[20:], 0)\n\n\t// Randomize record\n\tdata := make([]byte, rl-emptyRecordLen)\n\tif n, err := rand.Read(data); err != nil {\n\t\treturn err\n\t} else if n != len(data) {\n\t\treturn fmt.Errorf(\"not enough overwrite bytes read (%d != %d)\", n, len(data))\n\t}\n\n\t// Now write to underlying buffer.\n\tvar b bytes.Buffer\n\tb.Write(hdr[:])\n\tb.Write(data)\n\n\t// Calculate hash.\n\tmb.hh.Reset()\n\tmb.hh.Write(hdr[4:20])\n\tmb.hh.Write(data)\n\tvar hb [highwayhash.Size64]byte\n\tchecksum := mb.hh.Sum(hb[:0])\n\t// Write to msg record.\n\tb.Write(checksum)\n\n\t// Update both cache and disk.\n\tnbytes := b.Bytes()","sourceCodeStart":6759,"sourceCodeEnd":6795,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/filestore.go#L6759-L6795","documentation":"Thrown when overwriting a deleted/empty record: the store randomizes the record body with rand.Read before writing it over the old data (data shredding), and the entropy source returned fewer bytes than requested. The overwrite is aborted so no partially-randomized record is persisted.","triggerScenarios":"Purging/removing messages from a file-store block where the overwrite path randomizes len(data) bytes and rand.Read returns n < len(data) without an error.","commonSituations":"Host entropy exhaustion or blocked getrandom during message purge/trim operations on large blocks.","solutions":["Fix the host entropy source (getrandom//dev/urandom health) and retry the purge","Restart the server process once the randomness subsystem is healthy","Avoid sandbox/seccomp configurations that block system randomness syscalls","If reproducible, upgrade OS/Go runtime for modern crypto/rand guarantees"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Go: purge/trim calls can surface entropy faults\nif err := purgeOrTrim(msgs); err != nil {\n    if strings.Contains(err.Error(), \"not enough overwrite bytes\") {\n        // entropy source fault: fix host randomness, then retry purge\n    }\n    return err\n}","preventionTips":["Monitor entropy health on hosts doing frequent purges","Avoid seccomp profiles blocking getrandom","Restart processes after entropy recovery","Keep kernels/runtime up to date"],"tags":["crypto","entropy","purge","filestore"],"backgroundTag":"entropy-short-read","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}