Skip to content

Commit fd68a88

Browse files
committed
fix(eventStore): correct backwards read bounds check
Replaced invalid guard `@current_version < @from_position + @count` with proper range validation `@from_position < 0 OR @from_position > @current_version`. Previous logic incorrectly returned no results when valid messages existed. New check correctly validates start position independently of page size.
1 parent ea33765 commit fd68a88

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/SqlServer/src/Eventuous.SqlServer/Scripts/5_ReadStreamBackwards.sql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ BEGIN
2222
;THROW 50001, 'StreamNotFound', 1;
2323
END;
2424

25-
IF @current_version < @from_position + @count
25+
-- nothing to read / invalid request
26+
IF @count <= 0
27+
BEGIN
28+
RETURN;
29+
END;
30+
31+
-- Validate the starting position for backwards read.
32+
IF @from_position < 0 -- A negative starting position is invalid
33+
OR @from_position > @current_version -- A starting position greater than the current version means we're trying to read from beyond the head of the stream
2634
BEGIN
2735
RETURN;
2836
END;

0 commit comments

Comments
 (0)