{"record":{"id":"c31dea3037e1a2db","repo":"AdguardTeam/AdGuardHome","slug":"length-of-the-data-is-less-than-expected-got-d","errorCode":null,"errorMessage":"length of the data is less than expected: got %d","messagePattern":"length of the data is less than expected: got (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/aghuser/sessionstorage.go","lineNumber":285,"sourceCode":"\n// bboltBucketSessions is the name of the bucket storing web user sessions in\n// the bbolt database.\nconst bboltBucketSessions = \"sessions-2\"\n\nconst (\n\t// bboltSessionExpireLen is the length of the expire field in the binary\n\t// entry stored in bbolt.\n\tbboltSessionExpireLen = 4\n\n\t// bboltSessionNameLen is the length of the name field in the binary entry\n\t// stored in bbolt.\n\tbboltSessionNameLen = 2\n)\n\n// bboltDecode deserializes decodes a binary data into a session.\nfunc bboltDecode(data []byte) (s *Session, err error) {\n\tif len(data) < bboltSessionExpireLen+bboltSessionNameLen {\n\t\treturn nil, fmt.Errorf(\"length of the data is less than expected: got %d\", len(data))\n\t}\n\n\texpireData := data[:bboltSessionExpireLen]\n\tnameLenData := data[bboltSessionExpireLen : bboltSessionExpireLen+bboltSessionNameLen]\n\tnameData := data[bboltSessionExpireLen+bboltSessionNameLen:]\n\n\tnameLen := binary.BigEndian.Uint16(nameLenData)\n\tif len(nameData) != int(nameLen) {\n\t\treturn nil, fmt.Errorf(\"login: expected length %d, got %d\", nameLen, len(nameData))\n\t}\n\n\texpire := binary.BigEndian.Uint32(expireData)\n\n\treturn &Session{\n\t\tExpire:    time.Unix(int64(expire), 0),\n\t\tUserLogin: Login(nameData),\n\t}, nil\n}","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/aghuser/sessionstorage.go#L267-L303","documentation":"bboltDecode rejects a stored session record whose binary length is shorter than the minimum encoding (4-byte expire + 2-byte name length). It means the value stored in the sessions bucket is not a session serialized by bboltEncode — data corruption or a foreign/incompatible writer.","triggerScenarios":"processSessions / FindByToken decode a bucket value that is 0–5 bytes long; caused by truncated writes, manual tampering with the db, or an older format written by a previous version.","commonSituations":"Downgrade to an older AdGuard Home after a newer version changed the session encoding; editing session.db with external bbolt tooling; power loss truncating the file.","solutions":["Delete the sessions database file (sessions are non-critical) and restart","Check for version mismatch: upgrade path must be forward-only; redeploy the matching version","Verify db integrity with bbolt check / restore from backup"],"exampleFix":"rm /var/lib/adguardhome/sessions.db # sessions are recreated on next login","handlingStrategy":"fallback","validationCode":null,"typeGuard":"func isValidSessionData(b []byte) bool { return len(b) >= 6 }","tryCatchPattern":"// on decode-length errors, delete the offending session file/db and let users re-login\nif err != nil && strings.Contains(err.Error(), \"length of the data is less than expected\") { os.Remove(dbPath) }","preventionTips":["Never downgrade AdGuard Home versions","Don't write to session.db with external tools","Handle unclean shutdowns with clean restarts"],"tags":["bbolt","serialization","corruption","sessions"],"backgroundTag":"data-deserialization-failed","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}