Skip to content

Commit bc86807

Browse files
committed
8340554: Improve MessageFormat readObject checks
Backport-of: 7af46a6b424cadfe298958d774da0f21db58ecd3
1 parent cca69f3 commit bc86807

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
@@ -1637,7 +1637,7 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
16371637

16381638
// Check the correctness of arguments and offsets
16391639
if (isValid) {
1640-
int lastOffset = patt.length() + 1;
1640+
int lastOffset = patt.length();
16411641
for (int i = maxOff; i >= 0; --i) {
16421642
if (argNums[i] < 0 || argNums[i] >= MAX_ARGUMENT_INDEX
16431643
|| 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)