Skip to content

Commit a4974d4

Browse files
committed
Address review comments
The newly introduced Compilation Server message type VM_getStringUTF8UnabbreviatedLength is never acutally used. This change removes it along with the VM_getStringUTF8Length message type, which is also never used. This change also adjusts the maximum length for a UTF-8 encoding that can be returned by getStringUTF8Length from 2^31-1 to 2^31-2. That ensures that any code that then uses that length to allocate buffer to contain the encoded String with a NUL terminator will not overflow a 32-bit signed integer representation for the length plus the NUL byte. Signed-off-by: Henry Zongaro <[email protected]>
1 parent 1921662 commit a4974d4

File tree

5 files changed

+6
-26
lines changed

5 files changed

+6
-26
lines changed

runtime/compiler/control/JITClientCompilationThread.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -630,24 +630,6 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
630630
client->write(response, fe->stackWalkerMaySkipFrames(method, clazz));
631631
}
632632
break;
633-
case MessageType::VM_getStringUTF8Length:
634-
{
635-
uintptr_t string = std::get<0>(client->getRecvData<uintptr_t>());
636-
{
637-
TR::VMAccessCriticalSection getStringUTF8Length(fe);
638-
client->write(response, fe->getStringUTF8Length(string));
639-
}
640-
}
641-
break;
642-
case MessageType::VM_getStringUTF8UnabbreviatedLength:
643-
{
644-
uintptr_t string = std::get<0>(client->getRecvData<uintptr_t>());
645-
{
646-
TR::VMAccessCriticalSection getStringUTF8UnabbreviatedLength(fe);
647-
client->write(response, fe->getStringUTF8UnabbreviatedLength(string));
648-
}
649-
}
650-
break;
651633
case MessageType::VM_classInitIsFinished:
652634
{
653635
TR_OpaqueClassBlock *clazz = std::get<0>(client->getRecvData<TR_OpaqueClassBlock *>());

runtime/compiler/env/VMJ9.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5656,7 +5656,9 @@ TR_J9VMBase::getStringUTF8Length(uintptr_t objectPointer)
56565656
TR_ASSERT(objectPointer, "assertion failure");
56575657
uint64_t actualLength = vmThread()->javaVM->internalVMFunctions->getStringUTF8LengthTruncated(vmThread(), (j9object_t)objectPointer, INT64_MAX);
56585658

5659-
TR_ASSERT_FATAL(actualLength <= std::numeric_limits<int32_t>::max(), "UTF8-encoded String length of " UINT64_PRINTF_FORMAT " must be in the range permitted for type int32_t.\n", actualLength);
5659+
// Fail if length+1 cannot be represented as an int32_t value. The extra byte accounts for
5660+
// any NUL terminator that might be needed in copying the UTF-8 encoded string into a buffer
5661+
TR_ASSERT_FATAL(actualLength+1 <= std::numeric_limits<int32_t>::max(), "UTF8-encoded String length of " UINT64_PRINTF_FORMAT " must be in the range permitted for type int32_t, also allowing for a NUL terminator.\n", actualLength);
56605662

56615663
return (int32_t) actualLength;
56625664
}
@@ -5671,7 +5673,7 @@ TR_J9VMBase::getStringUTF8UnabbreviatedLength(uintptr_t objectPointer)
56715673
}
56725674

56735675
char *
5674-
TR_J9VMBase::getStringUTF8(uintptr_t objectPointer, char *buffer, int32_t bufferSize)
5676+
TR_J9VMBase::getStringUTF8(uintptr_t objectPointer, char *buffer, uintptr_t bufferSize)
56755677
{
56765678
TR_ASSERT(haveAccess(), "Must have VM access to call getStringUTF8");
56775679

runtime/compiler/env/VMJ9.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ class TR_J9VMBase : public TR_FrontEnd
11441144
/**
11451145
* \brief Returns the number of UTF-8 encoded bytes needed to represent a Java String object.
11461146
* The number of bytes needed to UTF-8 encode the String is representable as
1147-
* a \c uintptr_t, in general, but this method returns a length of type \c int32_t.
1147+
* a \c uint64_t, in general, but this method returns a length of type \c int32_t.
11481148
* If the length might exceed the range of \c int32_t, use
11491149
* \ref getStringUTF8UnabbreviatedLength instead.
11501150
*
@@ -1162,7 +1162,7 @@ class TR_J9VMBase : public TR_FrontEnd
11621162
* \return The number of UTF-8 encoded bytes needed to represent the String
11631163
*/
11641164
virtual uint64_t getStringUTF8UnabbreviatedLength(uintptr_t objectPointer);
1165-
virtual char *getStringUTF8 (uintptr_t objectPointer, char *buffer, int32_t bufferSize);
1165+
virtual char *getStringUTF8(uintptr_t objectPointer, char *buffer, uintptr_t bufferSize);
11661166

11671167
virtual uint32_t getVarHandleHandleTableOffset(TR::Compilation *);
11681168

runtime/compiler/net/MessageTypes.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ const char *messageNames[] =
121121
"VM_getObjectClassFromKnownObjectIndexJLClass",
122122
"VM_getObjectClassInfoFromObjectReferenceLocation",
123123
"VM_stackWalkerMaySkipFrames",
124-
"VM_getStringUTF8Length",
125-
"VM_getStringUTF8UnabbreviatedLength",
126124
"VM_classInitIsFinished",
127125
"VM_getClassFromNewArrayType",
128126
"VM_getArrayClassFromComponentClass",

runtime/compiler/net/MessageTypes.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ enum MessageType : uint16_t
130130
VM_getObjectClassFromKnownObjectIndexJLClass,
131131
VM_getObjectClassInfoFromObjectReferenceLocation,
132132
VM_stackWalkerMaySkipFrames,
133-
VM_getStringUTF8Length,
134-
VM_getStringUTF8UnabbreviatedLength,
135133
VM_classInitIsFinished,
136134
VM_getClassFromNewArrayType,
137135
VM_getArrayClassFromComponentClass,

0 commit comments

Comments
 (0)