Skip to content

8340554: Improve MessageFormat readObject checks #3767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/text/MessageFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE

// Check the correctness of arguments and offsets
if (isValid) {
int lastOffset = patt.length() + 1;
int lastOffset = patt.length();
for (int i = maxOff; i >= 0; --i) {
if (argNums[i] < 0 || argNums[i] >= MAX_ARGUMENT_INDEX
|| offs[i] < 0 || offs[i] > lastOffset) {
Expand Down
10 changes: 8 additions & 2 deletions test/jdk/java/text/Format/MessageFormat/SerializationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/*
* @test
* @bug 8331446
* @bug 8331446 8340554
* @summary Check correctness of deserialization
* @run junit SerializationTest
*/
Expand Down Expand Up @@ -70,7 +70,13 @@ private static Stream<MessageFormat> serializationRoundTrip() {
// With null locale. (NPE not thrown, if no format defined)
new MessageFormat("{1} {0} foo", null),
// With formats
new MessageFormat("{0,number,short} {0} {1,date,long} foo")
new MessageFormat("{0,number,short} {0} {1,date,long} foo"),
// Offset equal to pattern length (0)
new MessageFormat("{0}"),
// Offset equal to pattern length (1)
new MessageFormat("X{0}"),
// Offset 1 under pattern length
new MessageFormat("X{0}X")
);
}

Expand Down