From a19f77c5356785a7bdad621ebb9f0511bc8899bc Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Mon, 20 Apr 2026 20:45:41 -0400 Subject: [PATCH] fix(sync): prevent nil pointer dereference when existing progress is missing In applyProgressResolution and applyResolution, currentPage and totalPages were unconditionally read from existingProgress even when the preceding query returned err (no rows). This caused a nil pointer dereference when no existing reading progress existed for a media item. Now declare the variables as zero-value pgtype.Int4 and only populate them from existingProgress when err is nil. --- internal/handlers/conflicts.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/handlers/conflicts.go b/internal/handlers/conflicts.go index d3acdb2..446ca46 100644 --- a/internal/handlers/conflicts.go +++ b/internal/handlers/conflicts.go @@ -316,8 +316,12 @@ func (h *ConflictHandler) applyProgressResolution(mediaItemID pgtype.UUID, userI characterOffset = pgtype.Int8{Int64: int64(c), Valid: true} } - currentPage := existingProgress.CurrentPage - totalPages := existingProgress.TotalPages + var currentPage pgtype.Int4 + var totalPages pgtype.Int4 + if err == nil { + currentPage = existingProgress.CurrentPage + totalPages = existingProgress.TotalPages + } if p, ok := data["page"].(float64); ok { currentPage = pgtype.Int4{Int32: int32(p), Valid: true} @@ -661,8 +665,12 @@ func (h *ConflictHandler) applyResolution(mediaItemID pgtype.UUID, userID pgtype characterOffset = pgtype.Int8{Int64: int64(c), Valid: true} } - currentPage := existingProgress.CurrentPage - totalPages := existingProgress.TotalPages + var currentPage pgtype.Int4 + var totalPages pgtype.Int4 + if err == nil { + currentPage = existingProgress.CurrentPage + totalPages = existingProgress.TotalPages + } if p, ok := data["page"].(float64); ok { currentPage = pgtype.Int4{Int32: int32(p), Valid: true}