Skip to content

Commit ab291f5

Browse files
committed
8340554: Improve MessageFormat readObject checks
Backport-of: 7af46a6b424cadfe298958d774da0f21db58ecd3
1 parent 43f358f commit ab291f5

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
16621662

16631663
// Check the correctness of arguments and offsets
16641664
if (isValid) {
1665-
int lastOffset = patt.length() + 1;
1665+
int lastOffset = patt.length();
16661666
for (int i = maxOff; i >= 0; --i) {
16671667
if (argNums[i] < 0 || argNums[i] >= MAX_ARGUMENT_INDEX
16681668
|| offs[i] < 0 || offs[i] > lastOffset) {

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

Lines changed: 8 additions & 2 deletions
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)