You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2026/06/14 06:05:27 UTC
(poi) 09/11: Add some JavaDoc and tests for changes in VBAMacroReader
This is an automated email from the ASF dual-hosted git repository.
centic9 pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
commit 2810c299ff52e98060d530dd1e6f848c17960eac
Author: Dominik Stadler <ds...@apache.org>
AuthorDate: Sun Apr 12 20:50:41 2026 +0200
Add some JavaDoc and tests for changes in VBAMacroReader
---
.../apache/poi/poifs/macros/VBAMacroReader.java | 12 ++++++++++
.../poi/poifs/macros/TestVBAMacroReader.java | 27 ++++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java b/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java
index f422870f1c..7edadea0f5 100644
--- a/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java
+++ b/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java
@@ -74,10 +74,22 @@ public class VBAMacroReader implements Closeable {
private static final int DEFAULT_MAX_STRING_LENGTH = 20000;
private static int MAX_STRING_LENGTH = DEFAULT_MAX_STRING_LENGTH;
+ /**
+ * Set the maximum number of bytes to be allocated for a single VBA entry or decompressed
+ * stream. Use this to adjust the default limit if you need to process very large VBA projects,
+ * or to tighten the limit on memory-constrained systems.
+ *
+ * @param maxStringLength the maximum number of bytes that may be allocated; must be > 0
+ * @since 5.4.1
+ */
public static void setMaxStringLength(int maxStringLength) {
MAX_STRING_LENGTH = maxStringLength;
}
+ /**
+ * @return the maximum number of bytes that may be allocated per VBA entry or decompressed stream
+ * @since 5.4.1
+ */
public static int getMaxStringLength() {
return MAX_STRING_LENGTH;
}
diff --git a/poi/src/test/java/org/apache/poi/poifs/macros/TestVBAMacroReader.java b/poi/src/test/java/org/apache/poi/poifs/macros/TestVBAMacroReader.java
index 57e9ed814e..e867d3cf80 100644
--- a/poi/src/test/java/org/apache/poi/poifs/macros/TestVBAMacroReader.java
+++ b/poi/src/test/java/org/apache/poi/poifs/macros/TestVBAMacroReader.java
@@ -28,6 +28,10 @@ import static org.apache.poi.POITestCase.assertContains;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.poi.util.RecordFormatException;
import java.io.File;
import java.io.FileInputStream;
@@ -317,4 +321,27 @@ class TestVBAMacroReader {
assertEquals(20, macros.size());
r.close();
}
+
+ @Test
+ void maxStringLengthDefaultIsLarge() {
+ // Default should be large enough to handle real-world VBA projects
+ assertTrue(VBAMacroReader.getMaxStringLength() >= 20_000,
+ "Default MAX_STRING_LENGTH should be at least 20_000");
+ }
+
+ @Test
+ void setMaxStringLengthIsRespectedByModuleRead() throws IOException {
+ int prevLimit = VBAMacroReader.getMaxStringLength();
+ try {
+ // Set an absurdly small limit so the module stream read is rejected
+ VBAMacroReader.setMaxStringLength(1);
+ File f = POIDataSamples.getSpreadSheetInstance().getFile("SimpleMacro.xls");
+ try (VBAMacroReader r = new VBAMacroReader(f)) {
+ assertThrows(RecordFormatException.class, r::readMacros,
+ "Expected RecordFormatException when MAX_STRING_LENGTH is exceeded during module read");
+ }
+ } finally {
+ VBAMacroReader.setMaxStringLength(prevLimit);
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org