[JENKINS-73687] Make deserialization of Map fields in XML files more robust (#9653)

* Improve resilience against malformed XML files during deserialization

* Improve error message
This commit is contained in:
Devin Nusbaum authored and GitHub committed 2024-09-13 16:21:22 -06:00
1 parent d5271c8d2f
commit dab6597416
2 files changed
+52

No files matched your search

@@ -25,6 +25,7 @@
package hudson.util;
import com.thoughtworks.xstream.XStreamException;
import com.thoughtworks.xstream.converters.ConversionException;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.converters.collections.MapConverter;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
@@ -64,6 +65,12 @@ final class RobustMapConverter extends MapConverter {
}
private Object read(HierarchicalStreamReader reader, UnmarshallingContext context, Map map) {
if (!reader.hasMoreChildren()) {
var exception = new ConversionException("Invalid map entry");
reader.appendErrors(exception);
RobustReflectionConverter.addErrorInContext(context, exception);
return ERROR;
}
reader.moveDown();
try {
return readBareItem(reader, context, map);