Skip to content

Commit ccef910

Browse files
committed
Correction of serialVersionUID unmarshalling
serialVersionUID is a 64 bits (8 bytes) signed integer. newHandle doesn't exist in the file, it's just a grammatical indication.
1 parent 83d8466 commit ccef910

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

javaobj.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,18 @@ class JavaObjectUnmarshaller(JavaObjectConstants):
334334
"""
335335
Deserializes a Java serialization stream
336336
"""
337-
def __init__(self, stream=None):
337+
def __init__(self, stream):
338338
"""
339339
Sets up members
340340
341-
:param stream: An optional input stream (opened in binary/bytes mode)
341+
:param stream: An input stream (opened in binary/bytes mode)
342+
:raise IOError: Invalid input stream
342343
"""
344+
# Check stream
345+
if stream is None:
346+
raise IOError("No input stream given")
347+
348+
# Prepare the association Terminal Symbol -> Reading method
343349
self.opmap = {
344350
self.TC_NULL: self.do_null,
345351
self.TC_CLASSDESC: self.do_classdesc,
@@ -353,17 +359,24 @@ def __init__(self, stream=None):
353359
# note that we are reusing do_null:
354360
self.TC_ENDBLOCKDATA: self.do_null,
355361
}
362+
363+
# Set up members
356364
self.current_object = None
357365
self.reference_counter = 0
358366
self.references = []
367+
self.object_transformers = []
359368
self.object_stream = stream
369+
370+
# Read the stream header (magic & version)
360371
self._readStreamHeader()
361-
self.object_transformers = []
362372

363373

364374
def readObject(self):
365375
"""
366376
Reads an object from the input stream
377+
378+
:return: The unmarshalled object
379+
:raise Exception: Any exception that occurred during unmarshalling
367380
"""
368381
try:
369382
# TODO: add expects
@@ -490,22 +503,19 @@ def do_classdesc(self, parent=None, ident=0):
490503
# obj_typecode fieldName className1
491504
clazz = JavaClass()
492505
log_debug("[classdesc]", ident)
493-
ba = self._readString()
494-
clazz.name = ba
495-
log_debug("Class name: %s" % ba, ident)
496-
(serialVersionUID, newHandle, classDescFlags) = self._readStruct(">LLB")
497-
498-
# FIXME: Fix for 1.6 ?
499-
if serialVersionUID == 0:
500-
serialVersionUID = newHandle
506+
class_name = self._readString()
507+
clazz.name = class_name
508+
log_debug("Class name: %s" % class_name, ident)
501509

510+
# serialVersionUID is a Java (signed) long => 8 bytes
511+
(serialVersionUID, classDescFlags) = self._readStruct(">qB")
502512
clazz.serialVersionUID = serialVersionUID
503513
clazz.flags = classDescFlags
504514

505515
self._add_reference(clazz)
506516

507-
log_debug("Serial: 0x{0:X} newHandle: 0x{1:X}. classDescFlags: 0x{2:X}"\
508-
.format(serialVersionUID, newHandle, classDescFlags), ident)
517+
log_debug("Serial: 0x{0:X} / {0:d} - classDescFlags: 0x{1:X}"\
518+
.format(serialVersionUID, classDescFlags), ident)
509519
(length,) = self._readStruct(">H")
510520
log_debug("Fields num: 0x{0:X}".format(length), ident)
511521

0 commit comments

Comments
 (0)