From 7c2b76949e97f741708bc28b9cb5d1b795a68852 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Thu, 19 Jan 2017 02:58:42 +0100 Subject: [PATCH] Make one more llXorBase64[StringsCorrect] case computable. When the input string is at most 1 byte (2 base64 characters), the result is computable because the first byte is always zero. --- lslopt/lslbasefuncs.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lslopt/lslbasefuncs.py b/lslopt/lslbasefuncs.py index 09c7c83..c186089 100644 --- a/lslopt/lslbasefuncs.py +++ b/lslopt/lslbasefuncs.py @@ -1800,11 +1800,14 @@ def llXorBase64(s, xor): if L2 == 0: # The input xor string starts with zero or one valid Base64 characters. # This produces garbage bytes (the first byte is zero though). - # We don't produce a result in this case. - raise ELSLCantCompute + if L1 > 2: + # We don't produce a result in this case. + raise ELSLCantCompute + L2 = 2 + xor = u'AA' - s = b64decode(s + u'='*(-L1 & 3)) - xor = b64decode(xor + u'='*(-L2 & 3)) + s = b64decode(s + u'=' * (-L1 & 3)) + xor = b64decode(xor + u'=' * (-L2 & 3)) L2 = len(xor) i = 0 @@ -1887,11 +1890,14 @@ def llXorBase64StringsCorrect(s, xor): if L2 == 0: # The input xor string starts with zero or one valid Base64 characters. # This produces garbage bytes (the first byte is zero though). - # We don't produce a result in this case. - raise ELSLCantCompute + if L1 > 2: + # We don't produce a result in this case. + raise ELSLCantCompute + L2 = 2 + xor = u'AA' - s = b64decode(s + u'='*(-L1 & 3)) - xor = b64decode(xor + u'='*(-L2 & 3)) + b'\x00' + s = b64decode(s + u'=' * (-L1 & 3)) + xor = b64decode(xor + u'=' * (-L2 & 3)) + b'\x00' i = 0 ret = b''