Skip to content

Commit a8929e9

Browse files
committed
Hex: Fix an infinite loop when the input is less than 16 bytes.
1 parent d8845e5 commit a8929e9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cle/backends/ihex.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
import logging
33
import re
44
import struct
5-
from typing import List, Optional, Tuple
5+
from typing import List, Optional, Tuple, TYPE_CHECKING
66

77
import archinfo
88

99
from cle.errors import CLEError
1010

1111
from .backend import Backend, register_backend
1212

13+
if TYPE_CHECKING:
14+
from io import BytesIO
15+
1316
log = logging.getLogger(name=__name__)
1417

1518
__all__ = ("Hex",)
@@ -161,11 +164,14 @@ def __init__(self, *args, ignore_missing_arch: bool = False, **kwargs):
161164
self._min_addr = min_addr
162165

163166
@staticmethod
164-
def seek_non_space_bytes(stream, length=0x10):
167+
def seek_non_space_bytes(stream: "BytesIO", length=0x10):
165168
data = b""
166169
stream.seek(0)
167170
while len(data) < length and stream:
168171
byte = stream.read(1)
172+
if not byte:
173+
# we have exhausted the stream
174+
break
169175
if re.match(rb"\s", byte) is not None:
170176
continue
171177

0 commit comments

Comments
 (0)