-
Notifications
You must be signed in to change notification settings - Fork 45
Fix NPE from Boolean auto-unboxing #3392
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Arthur Chan <[email protected]>
The method powsybl-core/sensitivity-analysis-api/src/main/java/com/powsybl/sensitivity/SensitivityFactor.java Lines 130 to 137 in 455fd74
The problem is, the same variable powsybl-core/sensitivity-analysis-api/src/main/java/com/powsybl/sensitivity/SensitivityFactor.java Lines 33 to 45 in 455fd74
Later, the code unconditionally unboxes it when calling the constructor: powsybl-core/sensitivity-analysis-api/src/main/java/com/powsybl/sensitivity/SensitivityFactor.java Lines 159 to 162 in 455fd74
If the input JSON is missing the |
This is a stability issue caused by insufficient validation during the conversion between primitive and object variables. In many cases, object wrappers for primitive types accept a wider range of values than their primitive counterparts. For example, a Below is a Proof of Concept (PoC) demonstrating the issue. It calls the import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.powsybl.sensitivity.SensitivityFactor;
import java.io.StringReader;
public class ProofOfConcept {
public static void main(String[] args) throws Exception {
String json = """
{
"functionType": "BUS_VOLTAGE",
"functionId": "branch1",
"variableType": "BUS_TARGET_VOLTAGE",
"variableId": "gen1",
"contingencyContextType": "NONE"
}
""";
JsonFactory factory = new JsonFactory();
JsonParser parser = factory.createParser(new StringReader(json));
parser.nextToken();
SensitivityFactor.parseJson(parser);
}
} To execute and test the PoC, follow the steps below. It is assumed that OpenJDK 17.0.2 and Maven 3.9.9 is used.
You will get the following exception stack trace.
|
The issue stems from the constructor of the Here are two proposed fixes for different situations. Fix 1 – Null Values Not Permitted:
Fix 2 – Null Values Default to
Fix 1 is used in this PR, we can change the fix to Fix 2 if needed. |
This is a proposed fix to stability issue discovered by OSS-Fuzz when fuzzing the powsybl-core module. The original OSS-Fuzz issue can be found in https://issues.oss-fuzz.com/u/1/issues/406871272 and https://issues.oss-fuzz.com/u/1/issues/406999127.
Remark This fix could also be done by defaulting
variableSet
tofalse
if it is found missing from the JSON.