Skip to content

Commit 7af46a6

Browse files
author
Justin Lu
committedOct 24, 2024
8340554: Improve MessageFormat readObject checks
Reviewed-by: naoto
1 parent 7d5eefa commit 7af46a6

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed
 

‎src/java.base/share/classes/java/text/MessageFormat.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2041,7 +2041,7 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
20412041

20422042
// Check the correctness of arguments and offsets
20432043
if (isValid) {
2044-
int lastOffset = patt.length() + 1;
2044+
int lastOffset = patt.length();
20452045
for (int i = maxOff; i >= 0; --i) {
20462046
if (argNums[i] < 0 || argNums[i] >= MAX_ARGUMENT_INDEX
20472047
|| offs[i] < 0 || offs[i] > lastOffset) {

‎test/jdk/java/text/Format/MessageFormat/SerializationTest.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 8331446
26+
* @bug 8331446 8340554
2727
* @summary Check correctness of deserialization
2828
* @run junit SerializationTest
2929
*/
@@ -70,7 +70,13 @@ private static Stream<MessageFormat> serializationRoundTrip() {
7070
// With null locale. (NPE not thrown, if no format defined)
7171
new MessageFormat("{1} {0} foo", null),
7272
// With formats
73-
new MessageFormat("{0,number,short} {0} {1,date,long} foo")
73+
new MessageFormat("{0,number,short} {0} {1,date,long} foo"),
74+
// Offset equal to pattern length (0)
75+
new MessageFormat("{0}"),
76+
// Offset equal to pattern length (1)
77+
new MessageFormat("X{0}"),
78+
// Offset 1 under pattern length
79+
new MessageFormat("X{0}X")
7480
);
7581
}
7682

0 commit comments

Comments
 (0)
Please sign in to comment.