Skip to content
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

JUnpickler BufferOverflowException ByteBufferInputStream #1201

Open
tachyonicClock opened this issue Jul 4, 2024 · 0 comments
Open

JUnpickler BufferOverflowException ByteBufferInputStream #1201

tachyonicClock opened this issue Jul 4, 2024 · 0 comments

Comments

@tachyonicClock
Copy link
Contributor

When adding multiple java objects to a pickle a buffer overflow can occur. I believe this to be a bug related to native/java/org/jpype/pickle/ByteBufferInputStream.java specifically how it resizes after multiple puts.

import jpype
import jpype.imports
from jpype.pickle import JPickler, JUnpickler

if not jpype.isJVMStarted():
    jpype.startJVM(jpype.getDefaultJVMPath())

from java.lang import String


my_a = String('A' * 512)
my_b = String('B' * 512)

class PythonObject():

    def __init__(self, a, b):
        self.a = a
        self.b = b


with open('test.pkl', 'wb') as f:
    JPickler(f).dump(PythonObject(my_a, my_b))

try:
    with open('test.pkl', 'rb') as f:
        obj = JUnpickler(f).load()
except Exception as ex:
    print(ex.stacktrace())
java.nio.BufferOverflowException
	at java.base/java.nio.HeapByteBuffer.put(HeapByteBuffer.java:231)
	at java.base/java.nio.ByteBuffer.put(ByteBuffer.java:1210)
	at org.jpype.pickle.ByteBufferInputStream.put(Unknown Source)
	at org.jpype.pickle.Decoder.unpack(Unknown Source)
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

No branches or pull requests

1 participant