mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(cloudwatch): keep GetLogEvents paging inside the list bounds (#2355)
GetLogEvents ends a page at Math.min(pageStart + maxEvents, total), and maxEvents is Math.min(limit > 0 ? limit : Integer.MAX_VALUE, maxEventsPerQuery). A max-events cap configured near Integer.MAX_VALUE, the natural way to express "no cap" since the setting has no upper bound, makes pageStart + maxEvents overflow negative as soon as a forward token moves pagination past the first page. subList then throws IllegalArgumentException and the call fails with a 500. The end of the stream is where a client meets this rather than some deep page: GetLogEvents echoes its forward token when nothing is left, so a paginator always spends one more call on the token it was just handed. Take the window out of what remains instead of adding to the offset, which keeps both operands within the list's own bounds. The backward and tail branches already subtract and clamp, so they are unaffected, and behaviour at the default cap of 10000 is unchanged. The regression test drives the second paginator call under an unbounded cap, and fails without the fix with fromIndex(3) > toIndex(-2147483646).
This commit is contained in:
2 files changed
+37
-1
No files matched your search
+4
-1
@@ -428,7 +428,10 @@ public class CloudWatchLogsService {
|
||||
if (nextToken != null && nextToken.startsWith("f/")) {
|
||||
int offset = parseTokenIndex(nextToken, 2);
|
||||
pageStart = Math.min(offset, total);
|
||||
pageEnd = Math.min(pageStart + maxEvents, total);
|
||||
// Take the window out of what is left rather than adding to the offset, so a
|
||||
// max-events cap configured near Integer.MAX_VALUE cannot overflow the end
|
||||
// index negative once pagination has moved past the first page.
|
||||
pageEnd = pageStart + Math.min(maxEvents, total - pageStart);
|
||||
} else if (nextToken != null && nextToken.startsWith("b/")) {
|
||||
int end = parseTokenIndex(nextToken, 2);
|
||||
pageEnd = Math.min(end, total);
|
||||
|
||||
Reference in new issue
Block a user