You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2026/07/13 17:19:08 UTC

(commons-compress) 02/02: Refactor magic numbers.

This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit fc9ae9fb6482fba9bbef923aaf6e578f170ae26a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jul 13 13:19:01 2026 -0400

    Refactor magic numbers.
---
 .../apache/commons/compress/archivers/sevenz/LZMADecoder.java  | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/LZMADecoder.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/LZMADecoder.java
index d56cc5176..6c00f931e 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/LZMADecoder.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/LZMADecoder.java
@@ -32,6 +32,10 @@
 
 final class LZMADecoder extends AbstractCoder {
 
+    private static final int LZMA_DICT_IDX = 1;
+    private static final int LZMA_DICT_LEN = 4;
+    private static final int LZMA_PROP_LEN = LZMA_DICT_IDX + LZMA_DICT_LEN;
+
     LZMADecoder() {
         super(LZMA2Options.class, Number.class);
     }
@@ -61,10 +65,10 @@ OutputStream encode(final OutputStream out, final Object opts) throws IOExceptio
     }
 
     private int getDictionarySize(final Coder coder) throws ArchiveException {
-        if (coder.properties.length < 5) {
-            throw new ArchiveException("LZMA properties too short (expected 5 bytes)");
+        if (coder.properties.length < LZMA_DICT_LEN + LZMA_DICT_IDX) {
+            throw new ArchiveException("LZMA properties too short (expected " + LZMA_PROP_LEN + " bytes)");
         }
-        final long dictionarySize = ByteUtils.fromLittleEndian(coder.properties, 1, 4);
+        final long dictionarySize = ByteUtils.fromLittleEndian(coder.properties, LZMA_DICT_IDX, LZMA_DICT_LEN);
         if (dictionarySize > LZMAInputStream.DICT_SIZE_MAX) {
             throw new ArchiveException("Dictionary larger than 4 GiB maximum size");
         }