Commit 6b3088feb8a218a60272d5a81e4c7e91fe74f039
1 parent
7a9cb922
olefile: fixed a bug in _list when a storage is empty
Showing
1 changed file
with
5 additions
and
3 deletions
oletools/thirdparty/olefile/olefile.py
| @@ -180,6 +180,7 @@ __version__ = '0.42' | @@ -180,6 +180,7 @@ __version__ = '0.42' | ||
| 180 | # 2015-01-24 v0.42 PL: - changed the default path name encoding from Latin-1 | 180 | # 2015-01-24 v0.42 PL: - changed the default path name encoding from Latin-1 |
| 181 | # to UTF-8 on Python 2.x (Unicode on Python 3.x) | 181 | # to UTF-8 on Python 2.x (Unicode on Python 3.x) |
| 182 | # - added path_encoding option to override the default | 182 | # - added path_encoding option to override the default |
| 183 | +# - fixed a bug in _list when a storage is empty | ||
| 183 | 184 | ||
| 184 | #----------------------------------------------------------------------------- | 185 | #----------------------------------------------------------------------------- |
| 185 | # TODO (for version 1.0): | 186 | # TODO (for version 1.0): |
| @@ -1826,19 +1827,20 @@ class OleFileIO: | @@ -1826,19 +1827,20 @@ class OleFileIO: | ||
| 1826 | """ | 1827 | """ |
| 1827 | prefix = prefix + [node.name] | 1828 | prefix = prefix + [node.name] |
| 1828 | for entry in node.kids: | 1829 | for entry in node.kids: |
| 1829 | - #TODO: fix bug here, check entry type, a storage can have no kids | ||
| 1830 | - if entry.kids: | 1830 | + if entry.entry_type == STGTY_STORAGE: |
| 1831 | # this is a storage | 1831 | # this is a storage |
| 1832 | if storages: | 1832 | if storages: |
| 1833 | # add it to the list | 1833 | # add it to the list |
| 1834 | files.append(prefix[1:] + [entry.name]) | 1834 | files.append(prefix[1:] + [entry.name]) |
| 1835 | # check its kids | 1835 | # check its kids |
| 1836 | self._list(files, prefix, entry, streams, storages) | 1836 | self._list(files, prefix, entry, streams, storages) |
| 1837 | - else: | 1837 | + elif entry.entry_type == STGTY_STREAM: |
| 1838 | # this is a stream | 1838 | # this is a stream |
| 1839 | if streams: | 1839 | if streams: |
| 1840 | # add it to the list | 1840 | # add it to the list |
| 1841 | files.append(prefix[1:] + [entry.name]) | 1841 | files.append(prefix[1:] + [entry.name]) |
| 1842 | + else: | ||
| 1843 | + self._raise_defect(DEFECT_INCORRECT, 'The directory tree contains an entry which is not a stream nor a storage.') | ||
| 1842 | 1844 | ||
| 1843 | 1845 | ||
| 1844 | def listdir(self, streams=True, storages=False): | 1846 | def listdir(self, streams=True, storages=False): |