Repository navigation
Replace jbrotli Brotli codec with brotli4j for CVE-2026-111497 #3880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Devdha
wants to merge
6
commits into
apache:master
Choose a base branch
from
Devdha:security/brotli4j-codec
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+933
−40
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a4d4dc1
Replace jbrotli Brotli codec with brotli4j for CVE-2026-111497
Devdha 22b938d
Fix Brotli codec stream handling and large-page decoding
Devdha d9f8a1d
Bound Brotli decompression and fix stream contracts
Devdha 35e2079
Add Brotli codec regression tests for bounds and stream contracts
Devdha 93054b4
fix: preserve legacy Brotli codec class alias
Devdha 14ba766
fix: close failed Brotli streams and enforce output bounds
Devdha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...uet-common/src/test/java/org/apache/parquet/hadoop/metadata/TestCompressionCodecName.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.parquet.hadoop.metadata; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| import org.apache.parquet.hadoop.codec.CompressionCodecNotSupportedException; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class TestCompressionCodecName { | ||
|
|
||
| @Test | ||
| public void testLegacyBrotliCodecClassMapsToBrotli() { | ||
| assertThat(CompressionCodecName.fromCompressionCodecClassName("org.apache.hadoop.io.compress.BrotliCodec")) | ||
| .isEqualTo(CompressionCodecName.BROTLI); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBrotliCodecClassMapsToBrotli() { | ||
| assertThat(CompressionCodecName.fromCompressionCodecClassName("org.apache.parquet.hadoop.codec.BrotliCodec")) | ||
| .isEqualTo(CompressionCodecName.BROTLI); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCodecClassNamesRoundTrip() { | ||
| for (CompressionCodecName codec : CompressionCodecName.values()) { | ||
| if (codec.getHadoopCompressionCodecClassName() != null) { | ||
| assertThat(CompressionCodecName.fromCompressionCodecClassName( | ||
| codec.getHadoopCompressionCodecClassName())) | ||
| .isEqualTo(codec); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testUnknownCodecClass() { | ||
| assertThat(CompressionCodecName.fromCompressionCodecClassName(String.class.getName())) | ||
| .isNull(); | ||
| assertThatThrownBy(() -> CompressionCodecName.fromCompressionCodec(String.class)) | ||
| .isInstanceOf(CompressionCodecNotSupportedException.class) | ||
| .hasMessage("codec not supported: java.lang.String"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNullCodecClassIsUncompressed() { | ||
| assertThat(CompressionCodecName.fromCompressionCodec(null)).isEqualTo(CompressionCodecName.UNCOMPRESSED); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,6 +174,12 @@ | |
| <artifactId>zstd-jni</artifactId> | ||
| <version>${zstd-jni.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.aayushatharva.brotli4j</groupId> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checked the package and it looks legit. Even it is optional, the licenses are also in line with the ASF requirements. |
||
| <artifactId>brotli4j</artifactId> | ||
| <version>${brotli4j.version}</version> | ||
| <optional>true</optional> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.google.guava</groupId> | ||
|
|
@@ -246,33 +252,4 @@ | |
| </plugins> | ||
| </build> | ||
|
|
||
| <profiles> | ||
| <!-- PARQUET-1975 Do not add brotli-codec for ARM64 architectures --> | ||
| <profile> | ||
| <id>non-aarch64</id> | ||
| <activation> | ||
| <os> | ||
| <arch>!aarch64</arch> | ||
| </os> | ||
| </activation> | ||
| <repositories> | ||
| <repository> | ||
| <id>jitpack.io</id> | ||
| <url>https://jitpack.io</url> | ||
| <name>Jitpack.io repository</name> | ||
| <!-- needed for brotli-codec --> | ||
| </repository> | ||
| </repositories> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.github.rdblue</groupId> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😆 @rdblue |
||
| <artifactId>brotli-codec</artifactId> | ||
| <version>${brotli-codec.version}</version> | ||
| <scope>runtime</scope> | ||
| <optional>true</optional> | ||
| </dependency> | ||
| </dependencies> | ||
| </profile> | ||
| </profiles> | ||
|
|
||
| </project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/codec/BrotliCodec.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.parquet.hadoop.codec; | ||
|
|
||
| import com.aayushatharva.brotli4j.Brotli4jLoader; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.OutputStream; | ||
| import org.apache.hadoop.conf.Configurable; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.io.compress.CompressionCodec; | ||
| import org.apache.hadoop.io.compress.CompressionInputStream; | ||
| import org.apache.hadoop.io.compress.CompressionOutputStream; | ||
| import org.apache.hadoop.io.compress.Compressor; | ||
| import org.apache.hadoop.io.compress.Decompressor; | ||
| import org.apache.parquet.hadoop.BadConfigurationException; | ||
|
|
||
| /** | ||
| * Hadoop codec for Brotli, backed by the maintained brotli4j native bindings. | ||
| * | ||
| * <p>The previous implementation depended on the abandoned jbrotli-based brotli-codec artifact, | ||
| * which bundled an old Brotli decoder. This codec is loaded reflectively by {@link | ||
| * org.apache.parquet.hadoop.CodecFactory} and only requires brotli4j when Brotli is actually used. | ||
| */ | ||
| public class BrotliCodec implements CompressionCodec, Configurable { | ||
|
|
||
| public static final String BROTLI_QUALITY = "compression.brotli.quality"; | ||
| public static final int DEFAULT_QUALITY = 1; | ||
| private static final int DEFAULT_MAX_OUTPUT_SIZE = Integer.MAX_VALUE - 8; | ||
|
|
||
| private Configuration conf; | ||
| private int quality = DEFAULT_QUALITY; | ||
|
|
||
| @Override | ||
| public void setConf(Configuration conf) { | ||
| this.conf = conf; | ||
| if (conf != null) { | ||
| quality = conf.getInt(BROTLI_QUALITY, DEFAULT_QUALITY); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Configuration getConf() { | ||
| return conf; | ||
| } | ||
|
|
||
| @Override | ||
| public CompressionOutputStream createOutputStream(OutputStream out) throws IOException { | ||
| if (quality < 0 || quality > 11) { | ||
| throw new BadConfigurationException("Invalid Brotli compression quality: " + quality + ". Expected 0..11."); | ||
| } | ||
| ensureBrotliAvailable(); | ||
| try { | ||
| return new BrotliCompressionOutputStream(out, quality); | ||
| } catch (LinkageError e) { | ||
| throw missingBrotli(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public CompressionOutputStream createOutputStream(OutputStream out, Compressor compressor) throws IOException { | ||
| return createOutputStream(out); | ||
| } | ||
|
|
||
| @Override | ||
| public Class<? extends Compressor> getCompressorType() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Compressor createCompressor() { | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Decodes a complete Brotli stream into memory. Callers that handle untrusted data should use | ||
| * {@link #createInputStream(InputStream, int)} so the decoded output is bounded by the size they | ||
| * expect. | ||
| */ | ||
| @Override | ||
| public CompressionInputStream createInputStream(InputStream in) throws IOException { | ||
| return createInputStream(in, DEFAULT_MAX_OUTPUT_SIZE); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a decoder with an upper bound on the decompressed size. Parquet passes the size from | ||
| * the page header, so a crafted page cannot expand without limit during decoding. | ||
| * | ||
| * @throws IOException if the bound is negative or the decoded output exceeds it | ||
| */ | ||
| public CompressionInputStream createInputStream(InputStream in, int maxOutputSize) throws IOException { | ||
| ensureBrotliAvailable(); | ||
| try { | ||
| return new BrotliCompressionInputStream(in, maxOutputSize); | ||
| } catch (LinkageError e) { | ||
| throw missingBrotli(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public CompressionInputStream createInputStream(InputStream in, Decompressor decompressor) throws IOException { | ||
| return createInputStream(in); | ||
| } | ||
|
|
||
| @Override | ||
| public Class<? extends Decompressor> getDecompressorType() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Decompressor createDecompressor() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDefaultExtension() { | ||
| return ".br"; | ||
| } | ||
|
|
||
| private static void ensureBrotliAvailable() throws IOException { | ||
| try { | ||
| Brotli4jLoader.ensureAvailability(); | ||
| } catch (LinkageError e) { | ||
| throw missingBrotli(e); | ||
| } | ||
| } | ||
|
|
||
| private static IOException missingBrotli(LinkageError cause) { | ||
| return new IOException( | ||
| "Brotli codec requires the optional brotli4j dependency and its native library " | ||
| + "for this platform on the classpath", | ||
| cause); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming the class here changes how
CodecConfig.getHadoopCompressionCodec()resolvesmapred.output.compression.codec. That goes throughfromCompressionCodec(Class), which matches on the exact class name. A job that still hasmapred.output.compression.codec=org.apache.hadoop.io.compress.BrotliCodecset (with the old brotli-codec jar on its classpath) no longer matches. It hits theCompressionCodecNotSupportedExceptioncatch inCodecConfigand silently writes UNCOMPRESSED, with only a warning in the logs.Could we keep the old class name as an alias? Here's a patch with a small test;
TestBrotliCodecandTestDirectCodecFactorystill pass with it:Patch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied your suggested alias in 93054b4. The legacy class name now maps to
BROTLI, whileBROTLIcontinues to resolve to the new brotli4j-backed codec.Added the five regression tests for legacy/current class names, other codecs, unknown classes, and null. I confirmed that the legacy-name test fails without the alias and passes with it.
Validation:
parquet-common: all 337 tests passed.TestBrotliCodec(11), the fullTestDirectCodecFactory(15), andCodecConfigTest(1) all passed.spotless:checkpassed.The Hadoop test run used
-Denforcer.skip=truefor the pre-existing JUnit 4 imports inTestFooterIntegrity. The new GitHub Actions runs currently showaction_required.