chunkstore: an entry time past 2262 is unknown, not a wrapped value

Review: the catalog reader converted the entry's seconds to nanoseconds
without a range check, so an out-of-range mtime (year 9999) wrapped to a
negative time where the HTTP reader had reported it unknown (0). The
conversion is guarded; the master reader's refusal table has the
out-of-range case again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-25 17:55:42 -08:00
1 parent d08cee2315
commit b948bdac77
2 files changed
+6 -2

No files matched your search

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"math"
"path"
"strconv"
"strings"
@@ -64,7 +65,9 @@ func (s *LayoutStore) ReadHeadObserved(ctx context.Context) (h layout.Head, mtim
if err != nil {
return layout.Head{}, 0, false, err
}
if sec := e.GetAttributes().GetMtime(); sec > 0 {
// A time not representable in nanoseconds (past 2262) is unknown, as is
// none: it never wraps to a wrong value.
if sec := e.GetAttributes().GetMtime(); sec > 0 && sec <= math.MaxInt64/int64(1e9) {
mtimeNS = sec * int64(1e9)
}
return h, mtimeNS, true, nil
@@ -123,6 +123,7 @@ func TestWorkspaceLayoutHEADRefusalsAndStates(t *testing.T) {
{name: "detached", valid: true},
{name: "live", state: "live", valid: true},
{name: "unknown mtime", valid: true, alter: func(e *filerpb.Entry) { e.Attributes = nil }},
{name: "out-of-range mtime", valid: true, alter: func(e *filerpb.Entry) { e.Attributes = &filerpb.FuseAttributes{Mtime: 253402300799} }}, // year 9999
{name: "unclaimed", state: "unclaimed", sentinel: authority.ErrWorkspaceHeadUnclaimed},
{name: "deleted", state: layout.StateDeleted, sentinel: authority.ErrWorkspaceHeadDeleting},
{name: "missing generation", alter: func(e *filerpb.Entry) { delete(e.Extended, "swb.layout.gen") }},
@@ -182,7 +183,7 @@ func TestWorkspaceLayoutHEADRefusalsAndStates(t *testing.T) {
}
got, err := read(ctx, "v")
wantTime := int64(100e9)
if tc.name == "unknown mtime" {
if tc.name == "unknown mtime" || tc.name == "out-of-range mtime" {
wantTime = 0
}
switch {