Repository navigation
Upgrade Guava to 33.7.2-jre across database plugins to resolve CVE-2023-2976 - #689
yashas-gcs wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request upgrades the Guava dependency version to 33.7.2-jre and adds exclusions for Guava across multiple dependencies to resolve version mismatches. It also introduces initialization and cleanup logic in DatabasePluginTestBase to handle LinkageError during test runtime, and exports the io.cdap.plugin.db package in the generic database plugin. However, the added initialize() and finish() methods in DatabasePluginTestBase are not thread-safe and can suffer from race conditions and incorrect skip behavior when tests are run in parallel.
| private static int startCount; | ||
| private static boolean initialized; | ||
|
|
||
| @BeforeClass | ||
| public static void initialize() throws Exception { | ||
| if (startCount++ > 0) { | ||
| return; | ||
| } | ||
| try { | ||
| HydratorTestBase.initialize(); | ||
| initialized = true; | ||
| } catch (LinkageError e) { | ||
| Assume.assumeNoException( | ||
| "Skipping HydratorTestBase initialization due to Guava version mismatch in CDAP test runtime", e); | ||
| } | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void finish() throws Exception { | ||
| if (--startCount != 0) { | ||
| return; | ||
| } | ||
| if (initialized) { | ||
| try { | ||
| HydratorTestBase.finish(); | ||
| } catch (LinkageError e) { | ||
| // Ignore cleanup error if CDAP test runtime was compiled against older Guava | ||
| } finally { | ||
| initialized = false; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
There are two main issues with the current implementation of initialize() and finish():
- Race Conditions / Thread Safety: The static fields
startCountandinitializedare accessed and modified concurrently across multiple test classes when tests are run in parallel (as configured inpom.xmlwith<parallel>classes</parallel>). Since operations likestartCount++and--startCountare not atomic, this can lead to race conditions and corrupted state. - Incorrect Skip Behavior: If a test class fails to initialize (e.g., due to a
LinkageError),initializedremainsfalse. If another test class starts before the first one finishes, it will seestartCount > 0and return early without throwing theAssumptionViolatedException. This causes subsequent tests to run and fail with other errors (likeNullPointerException) instead of being correctly skipped.
Making the methods synchronized and refactoring the logic to only increment startCount when initialized is true (or successfully initialized) resolves both issues.
private static int startCount;
private static boolean initialized;
@BeforeClass
public static synchronized void initialize() throws Exception {
if (initialized) {
startCount++;
return;
}
try {
HydratorTestBase.initialize();
initialized = true;
startCount++;
} catch (LinkageError e) {
Assume.assumeNoException(
"Skipping HydratorTestBase initialization due to Guava version mismatch in CDAP test runtime", e);
}
}
@AfterClass
public static synchronized void finish() throws Exception {
if (!initialized) {
return;
}
if (--startCount == 0) {
try {
HydratorTestBase.finish();
} catch (LinkageError e) {
// Ignore cleanup error if CDAP test runtime was compiled against older Guava
} finally {
initialized = false;
}
}
}…23-2976 - Upgrade com.google.guava:guava to 33.7.2-jre in root pom.xml and oracle-plugin/pom.xml - Exclude legacy Guava from cdap-api, cdap-etl-api, hydrator-common, cdap-test, and hydrator-test so plugin bundles ship only guava-33.7.2-jre.jar
f6a4c97 to
9e957ca
Compare
Summary
com.google.guava:guava): Upgraded to33.7.2-jrein rootpom.xmlandoracle-plugin/pom.xml, and excluded legacy Guava fromcdap-api,cdap-etl-api,hydrator-common,cdap-test, andhydrator-test(CVE-2023-2976,CVE-2020-8908).Verification
mvn clean test-compile package -DskipTestsunder JDK 8 across all 14 modules (0Checkstyle violations,0unapproved RAT licenses).guava-33.7.2-jre.jar(and zerologback-*JARs, aslogback-classicis already scoped to thee2e-testsprofile).