Skip to content

Fix cross-heap free of userSuppliedTag in JniUtils::toTag - #368

Open
wonhong-choi wants to merge 1 commit into
openlvc:maintenance-2.2.xfrom
wonhong-choi:fix/jniutils-totag-heap-corruption
Open

Fix cross-heap free of userSuppliedTag in JniUtils::toTag#368
wonhong-choi wants to merge 1 commit into
openlvc:maintenance-2.2.xfrom
wonhong-choi:fix/jniutils-totag-heap-corruption

Conversation

@wonhong-choi

Copy link
Copy Markdown

The previous implementation allocated a buffer with new jbyte[size] (RTI DLL heap) and then discarded the pointer returned by GetByteArrayElements, passing the unrelated new[] pointer to ReleaseByteArrayElements instead. This caused the JVM to free a block from the wrong heap, resulting in STATUS_HEAP_CORRUPTION (0xC0000374) on every reflectAttributeValues/receiveInteraction/removeObjectInstance callback that carried a non-null userSuppliedTag.

Additionally, because GetByteArrayElements' return value was thrown away, buffer held uninitialized memory and the received tag bytes were never actually read.

Fix: capture the pointer GetByteArrayElements returns, build VariableLengthData from that pointer, then release that same pointer with JNI_ABORT. This matches the already-correct pattern used by toAttributeValueMap/toParameterValueMap in the same file.

The previous implementation allocated a buffer with `new jbyte[size]`
(RTI DLL heap) and then discarded the pointer returned by
GetByteArrayElements, passing the unrelated `new[]` pointer to
ReleaseByteArrayElements instead. This caused the JVM to free a block
from the wrong heap, resulting in STATUS_HEAP_CORRUPTION (0xC0000374)
on every reflectAttributeValues/receiveInteraction/removeObjectInstance
callback that carried a non-null userSuppliedTag.

Additionally, because GetByteArrayElements' return value was thrown
away, buffer held uninitialized memory and the received tag bytes were
never actually read.

Fix: capture the pointer GetByteArrayElements returns, build
VariableLengthData from that pointer, then release that same pointer
with JNI_ABORT. This matches the already-correct pattern used by
toAttributeValueMap/toParameterValueMap in the same file.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@michaelrfraser

Copy link
Copy Markdown
Contributor

Looks good to me thanks @wonhong-choi, thanks for your contribution!

@timpokorny this should also get cherry-picked to master?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants