-
Notifications
You must be signed in to change notification settings - Fork 45
Add null check for return value of CsvParser::parseLine #3393
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]>
A The problematic code is shown below. powsybl-core/psse/psse-model/src/main/java/com/powsybl/psse/model/io/AbstractRecordGroup.java Lines 171 to 174 in 455fd74
The loop assumes that each Thus, the missed validation of the null return value from CsvParser cause unexpected NullPointerException and that affect the stability of the code. |
The The proof-of-concept (PoC) code includes dummy classes to simulate the instantiation of the target object and calls to the problematic code. Since these methods are protected, the PoC must reside in the same package as the target class to facilitate testing. However, in practice, several call paths do not require this setup and could still eventually invoke the vulnerable method. package com.powsybl.psse.model.io;
import com.powsybl.psse.model.io.RecordGroupIdentification.JsonObjectType;
import com.univocity.parsers.csv.CsvParserSettings;
import java.util.Collections;
import java.util.List;
public class ProofOfConcept {
public static void main(String[] args) {
DummyRecordGroup group = new DummyRecordGroup();
List<String> records = Collections.singletonList(null);
group.parseRecords(records, new String[]{"field"}, new Context());
}
public static class DummyRecord {
private String field;
public String getField() { return field; }
public void setField(String field) { this.field = field; }
}
public static class DummyRecordGroup extends AbstractRecordGroup<DummyRecord> {
public DummyRecordGroup() {
super(new RecordGroupIdentification() {
@Override
public String getDataName() {
return "dummy";
}
@Override
public String getJsonNodeName() {
return "dummyJson";
}
@Override
public String getLegacyTextName() {
return "dummyLegacy";
}
@Override
public JsonObjectType getJsonObjectType() {
return JsonObjectType.DATA_TABLE;
}
}, "field");
}
@Override
protected Class<DummyRecord> psseTypeClass() {
return DummyRecord.class;
}
}
} |
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. Also, because of the protected status of the target method, the proof of concept class needed to be in the same package of the target class.
You will get the following exception stack trace.
|
The root cause is down at the |
Signed-off-by: Arthur Chan <[email protected]>
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/406925425.