Commit 63db719f0b9798f99f985449ac07d0b724a5ce30
Committed by
Philippe Lagadec
1 parent
29b08127
Clamp num_props to prevent excessive resource usage (#114)
A large num_props value will cause memory bloat (via the range usage) and potentially billions of useless logs in relaxed mode. Clamp it to a value that has a reasonable chance of working without generating exceptions.
Showing
1 changed file
with
4 additions
and
1 deletions
oletools/thirdparty/olefile/olefile.py
| ... | ... | @@ -2201,7 +2201,10 @@ class OleFileIO: |
| 2201 | 2201 | self._raise_defect(DEFECT_INCORRECT, msg, type(exc)) |
| 2202 | 2202 | return data |
| 2203 | 2203 | |
| 2204 | - for i in range(num_props): | |
| 2204 | + # clamp num_props based on the data length | |
| 2205 | + num_props = min(num_props, len(s) / 8) | |
| 2206 | + | |
| 2207 | + for i in xrange(num_props): | |
| 2205 | 2208 | property_id = 0 # just in case of an exception |
| 2206 | 2209 | try: |
| 2207 | 2210 | property_id = i32(s, 8+i*8) | ... | ... |