From 31c4bbf67175c4398df4603918fb7e582846a107 Mon Sep 17 00:00:00 2001 From: Matteo Merli Date: Mon, 3 Jun 2024 15:13:03 -0700 Subject: [PATCH] [improve] Validate range of argument before long -> int conversion --- .../pulsar/broker/admin/impl/TransactionsBase.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TransactionsBase.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TransactionsBase.java index 1014c9fe8e372..4fef0802ed413 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TransactionsBase.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/TransactionsBase.java @@ -564,8 +564,15 @@ protected CompletableFuture internalGetPositionStatsP protected CompletableFuture internalAbortTransaction(boolean authoritative, long mostSigBits, long leastSigBits) { + + if (mostSigBits < 0 || mostSigBits > Integer.MAX_VALUE) { + return CompletableFuture.failedFuture(new IllegalArgumentException("mostSigBits out of bounds")); + } + + int partitionIdx = (int) mostSigBits; + return validateTopicOwnershipAsync( - SystemTopicNames.TRANSACTION_COORDINATOR_ASSIGN.getPartition((int) mostSigBits), authoritative) + SystemTopicNames.TRANSACTION_COORDINATOR_ASSIGN.getPartition(partitionIdx), authoritative) .thenCompose(__ -> validateSuperUserAccessAsync()) .thenCompose(__ -> pulsar().getTransactionMetadataStoreService() .endTransaction(new TxnID(mostSigBits, leastSigBits), TxnAction.ABORT_VALUE, false));