Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.apache.logging.log4j.test.junit.SerialUtil;
import org.junit.jupiter.api.Test;

/**
Expand All @@ -38,4 +39,16 @@ void testGetParameters() {
void testGetThrowable() {
assertNull(OBJECT_ARRAY_MESSAGE.getThrowable());
}

/**
* Round-trips through a filtered stream (see {@link SerialUtil#getObjectInputStream})
* to verify that {@code readObject}'s new {@code SerializationUtil.assertFiltered}
* check accepts streams that carry a filter.
*/
@Test
void testSerializableRoundTripThroughFilteredStream() {
final ObjectArrayMessage original = new ObjectArrayMessage("A", "B", "C");
final ObjectArrayMessage restored = SerialUtil.deserialize(SerialUtil.serialize(original));
assertArrayEquals(original.getParameters(), restored.getParameters());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.ObjectOutputStream;
import java.util.Arrays;
import org.apache.logging.log4j.util.Constants;
import org.apache.logging.log4j.util.internal.SerializationUtil;

/**
* Handles messages that contain an Object[].
Expand Down Expand Up @@ -117,6 +118,7 @@ public int hashCode() {
}

private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
SerializationUtil.assertFiltered(in);
in.defaultReadObject();
array = (Object[]) in.readObject();
}
Expand Down
11 changes: 11 additions & 0 deletions src/changelog/.2.x.x/harden_message_deserialization.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="https://logging.apache.org/xml/ns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
https://logging.apache.org/xml/ns
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
type="changed">
<description format="asciidoc">
Hardened `ObjectArrayMessage.readObject()` to call `SerializationUtil.assertFiltered()` for consistency with `ObjectMessage` and `ParameterizedMessage`. Defense-in-depth only; wire format is unchanged.
</description>
</entry>