Preserve Delamain stale slice error responses

This commit is contained in:
takuya committed 2026-11-29 13:16:58 +03:00
1 parent 48c7ab4618
commit 527255f5b7
1 file changed
+6 -2
+6 -2
View File
@@ -86,18 +86,22 @@ func (g *apiGuard) readSlice(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusUnauthorized, "authentication required") writeError(w, http.StatusUnauthorized, "authentication required")
return return
} }
if request.Slot >= 32 {
writeJSON(w, http.StatusOK, map[string]any{"status": -1, "error": "invalid-slot"})
return
}
g.notesMu.Lock() g.notesMu.Lock()
note, found := g.notes[request.noteHandle] note, found := g.notes[request.noteHandle]
g.notesMu.Unlock() g.notesMu.Unlock()
if !found || time.Since(note.created) >= noteLifetime { if !found || time.Since(note.created) >= noteLifetime {
writeError(w, http.StatusForbidden, "note unavailable") writeJSON(w, http.StatusOK, map[string]any{"status": -2, "error": "stale-generation"})
return return
} }
if !g.requireTripOwner(w, r, note.tripID) { if !g.requireTripOwner(w, r, note.tripID) {
return return
} }
size := uint64(len(note.data)) size := uint64(len(note.data))
if request.Offset > size || request.Length > size-request.Offset { if request.Length == 0 || request.Offset >= size || request.Length > size-request.Offset {
writeJSON(w, http.StatusOK, map[string]any{"status": -4, "error": "out-of-bounds"}) writeJSON(w, http.StatusOK, map[string]any{"status": -4, "error": "out-of-bounds"})
return return
} }