Skip to content

Commit d5aa0fa

Browse files
committed
Fix review comment
1 parent ea55a8a commit d5aa0fa

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

java/src/org/openqa/selenium/grid/graphql/GraphqlHandler.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.io.InputStream;
4545
import java.io.UncheckedIOException;
4646
import java.net.URI;
47+
import java.nio.charset.StandardCharsets;
4748
import java.time.Duration;
4849
import java.util.HashMap;
4950
import java.util.Map;
@@ -114,7 +115,7 @@ public GraphqlHandler(
114115
String query = executionInput.getQuery();
115116

116117
// Query size validation with bypass for oversized queries
117-
if (query.getBytes().length > MAX_QUERY_SIZE_BYTES) {
118+
if (query.getBytes(StandardCharsets.UTF_8).length > MAX_QUERY_SIZE_BYTES) {
118119
// Bypass cache for oversized queries to prevent cache pollution
119120
return CompletableFuture.supplyAsync(
120121
() -> computeFunction.apply(executionInput));
@@ -265,8 +266,9 @@ public int weigh(String key, CompletableFuture<PreparsedDocumentEntry> value) {
265266

266267
long totalWeight = keyWeight + futureOverhead + documentOverhead;
267268

268-
// Bounds checking to prevent single entries from dominating cache
269-
return (int) Math.min(totalWeight, maxSingleEntryWeight);
269+
// Bounds checking to prevent single entries from dominating cache and integer overflow
270+
long boundedWeight = Math.min(totalWeight, maxSingleEntryWeight);
271+
return (int) Math.min(boundedWeight, Integer.MAX_VALUE);
270272
}
271273
}
272274
}

0 commit comments

Comments
 (0)