Commit 80bf761ae3ca0050e8951c15eb6030b535b4df24

Authored by decalage2
1 parent 6fcf5ada

rtfobj: ignore optional space after \bin (issue #185)

Showing 1 changed file with 7 additions and 2 deletions
oletools/rtfobj.py
@@ -75,6 +75,7 @@ http://www.decalage.info/python/oletools @@ -75,6 +75,7 @@ http://www.decalage.info/python/oletools
75 # 2017-06-29 PL: - temporary fix for issue #178 75 # 2017-06-29 PL: - temporary fix for issue #178
76 # 2017-07-14 v0.51.1 PL: - disabled logging of each control word (issue #184) 76 # 2017-07-14 v0.51.1 PL: - disabled logging of each control word (issue #184)
77 # 2017-07-24 PL: - fixed call to RtfParser._end_of_file (issue #185) 77 # 2017-07-24 PL: - fixed call to RtfParser._end_of_file (issue #185)
  78 +# - ignore optional space after \bin (issue #185)
78 79
79 __version__ = '0.51.1dev3' 80 __version__ = '0.51.1dev3'
80 81
@@ -509,15 +510,19 @@ class RtfParser(object): @@ -509,15 +510,19 @@ class RtfParser(object):
509 510
510 def _bin(self, matchobject, param): 511 def _bin(self, matchobject, param):
511 binlen = int(param) 512 binlen = int(param)
  513 + # handle negative length
512 if binlen < 0: 514 if binlen < 0:
513 log.warn('Detected anti-analysis trick: \\bin object with negative length at index %X' % self.index) 515 log.warn('Detected anti-analysis trick: \\bin object with negative length at index %X' % self.index)
514 # binlen = int(param.strip('-')) 516 # binlen = int(param.strip('-'))
515 # According to my tests, if the bin length is negative, 517 # According to my tests, if the bin length is negative,
516 # it should be treated as a null length: 518 # it should be treated as a null length:
517 binlen=0 519 binlen=0
  520 + # ignore optional space after \bin
  521 + if self.data[self.index] == ' ':
  522 + log.debug('\\bin: ignoring whitespace before data')
  523 + self.index += 1
518 log.debug('\\bin: reading %d bytes of binary data' % binlen) 524 log.debug('\\bin: reading %d bytes of binary data' % binlen)
519 - # TODO: handle optional space?  
520 - # TODO: handle negative length, and length greater than data 525 + # TODO: handle length greater than data
521 bindata = self.data[self.index:self.index + binlen] 526 bindata = self.data[self.index:self.index + binlen]
522 self.index += binlen 527 self.index += binlen
523 self.bin(bindata) 528 self.bin(bindata)