Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve BlocksByRangeMessage validation #9085

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,18 @@ public Optional<RpcException> validateRequest(
return Optional.of(new RpcException(INVALID_REQUEST_CODE, "Step must be greater than zero"));
}

final UInt64 maxRequestBlocks =
spec.forMilestone(latestMilestoneRequested).miscHelpers().getMaxRequestBlocks();
final int maxRequestBlocks =
spec.forMilestone(latestMilestoneRequested).miscHelpers().getMaxRequestBlocks().intValue();

int requestedCount;
try {
requestedCount = request.getCount().intValue();
} catch (final ArithmeticException __) {
// handle overflows
requestedCount = -1;
}

if (request.getCount().isGreaterThan(maxRequestBlocks)) {
if (requestedCount == -1 || requestedCount > maxRequestBlocks) {
requestCounter.labels("count_too_big").inc();
return Optional.of(
new RpcException(
Expand Down