From b43f5b8cf28a8fb8e3418536f0a45af5c5d526e4 Mon Sep 17 00:00:00 2001 From: Pascal Schumacher Date: Sun, 8 Mar 2020 11:50:21 +0100 Subject: [PATCH] Avoid potential overflow in int multiplication before it is converted to long. --- .../org/apache/activemq/broker/TransportStatusDetector.java | 2 +- .../src/main/java/org/apache/activemq/util/BitArrayBin.java | 2 +- .../org/apache/activemq/store/kahadb/disk/page/PageFile.java | 2 +- .../apache/activemq/store/kahadb/disk/page/Transaction.java | 2 +- .../apache/activemq/transport/mqtt/MQTTProtocolConverter.java | 2 +- .../src/main/java/org/apache/activemq/tool/JMSMemtest.java | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/TransportStatusDetector.java b/activemq-broker/src/main/java/org/apache/activemq/broker/TransportStatusDetector.java index 03eed944c2..1d0d3c3fa2 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/TransportStatusDetector.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/TransportStatusDetector.java @@ -118,7 +118,7 @@ public class TransportStatusDetector implements Service, Runnable { public void stop() throws Exception { started.set(false); if (runner != null) { - runner.join(getSweepInterval() * 5); + runner.join(getSweepInterval() * 5L); } } } diff --git a/activemq-client/src/main/java/org/apache/activemq/util/BitArrayBin.java b/activemq-client/src/main/java/org/apache/activemq/util/BitArrayBin.java index e19b8174bc..dcaccbd9b2 100644 --- a/activemq-client/src/main/java/org/apache/activemq/util/BitArrayBin.java +++ b/activemq-client/src/main/java/org/apache/activemq/util/BitArrayBin.java @@ -175,7 +175,7 @@ public class BitArrayBin implements Serializable { last = list.get(lastBitArrayIndex); if (last != null) { result += last.length() -1; - result += lastBitArrayIndex * BitArray.LONG_SIZE; + result += lastBitArrayIndex * (long) BitArray.LONG_SIZE; break; } } diff --git a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/page/PageFile.java b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/page/PageFile.java index 3f6a34d8f9..519a1a27e6 100644 --- a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/page/PageFile.java +++ b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/page/PageFile.java @@ -1237,7 +1237,7 @@ public class PageFile { } private long recoveryFileSizeForPages(int pageCount) { - return RECOVERY_FILE_HEADER_SIZE + ((pageSize + 8) * pageCount); + return RECOVERY_FILE_HEADER_SIZE + ((pageSize + 8L) * pageCount); } private void releaseCheckpointWaiter() { diff --git a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/page/Transaction.java b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/page/Transaction.java index c91020c22d..0f70103487 100644 --- a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/page/Transaction.java +++ b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/page/Transaction.java @@ -726,7 +726,7 @@ public class Transaction implements Iterable { Long key = page.getPageId(); // how much pages we have for this transaction - size = writes.size() * pageFile.getPageSize(); + size = writes.size() * (long) pageFile.getPageSize(); PageWrite write; diff --git a/activemq-mqtt/src/main/java/org/apache/activemq/transport/mqtt/MQTTProtocolConverter.java b/activemq-mqtt/src/main/java/org/apache/activemq/transport/mqtt/MQTTProtocolConverter.java index 1028c16961..b132fcdec6 100644 --- a/activemq-mqtt/src/main/java/org/apache/activemq/transport/mqtt/MQTTProtocolConverter.java +++ b/activemq-mqtt/src/main/java/org/apache/activemq/transport/mqtt/MQTTProtocolConverter.java @@ -694,7 +694,7 @@ public class MQTTProtocolConverter { // Client has sent a valid CONNECT frame, we can stop the connect checker. monitor.stopConnectChecker(); - long keepAliveMS = keepAliveSeconds * 1000; + long keepAliveMS = keepAliveSeconds * 1000L; LOG.debug("MQTT Client {} requests heart beat of {} ms", getClientId(), keepAliveMS); diff --git a/activemq-tooling/activemq-memtest-maven-plugin/src/main/java/org/apache/activemq/tool/JMSMemtest.java b/activemq-tooling/activemq-memtest-maven-plugin/src/main/java/org/apache/activemq/tool/JMSMemtest.java index a633695bcd..cc7dfbc8d4 100644 --- a/activemq-tooling/activemq-memtest-maven-plugin/src/main/java/org/apache/activemq/tool/JMSMemtest.java +++ b/activemq-tooling/activemq-memtest-maven-plugin/src/main/java/org/apache/activemq/tool/JMSMemtest.java @@ -95,7 +95,7 @@ public class JMSMemtest { reportName = settings.getProperty("reportName"); destinationName = settings.getProperty("destinationName"); reportDirectory = settings.getProperty("reportDirectory"); - connectionInterval = connectionCheckpointSize * 1024; + connectionInterval = connectionCheckpointSize * 1024L; } public static void main(String[] args) { @@ -171,7 +171,7 @@ public class JMSMemtest { protected boolean resetConnection(int counter) { if (connectionInterval > 0) { - long totalMsgSizeConsumed = counter * 1024; + long totalMsgSizeConsumed = counter * 1024L; if (connectionInterval < totalMsgSizeConsumed) { return true; }