Skip to content

Commit 43f0a58

Browse files
committed
daplink_flash: Enforce ASCII filenames and handle zero-length reads.
1 parent 4d1988a commit 43f0a58

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

lib/daplink_flash/daplink_flash/device.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ def _wait_busy(self, timeout_ms=30000):
7171
def set_filename(self, name, ext):
7272
"""Set 8.3 filename. name: max 8 chars, ext: max 3 chars."""
7373
self._wait_busy()
74-
n = name.upper()[:FILENAME_LEN]
75-
e = ext.upper()[:EXT_LEN]
76-
padded = n + " " * (FILENAME_LEN - len(n)) + e + " " * (EXT_LEN - len(e))
77-
self._write_reg(CMD_SET_FILENAME, padded.encode())
74+
n = name.upper().encode("ascii")[:FILENAME_LEN]
75+
e = ext.upper().encode("ascii")[:EXT_LEN]
76+
padded = n + b" " * (FILENAME_LEN - len(n)) + e + b" " * (EXT_LEN - len(e))
77+
self._write_reg(CMD_SET_FILENAME, padded)
7878

7979
def get_filename(self):
8080
"""Read current filename. Returns (name, ext) tuple, stripped."""
@@ -154,6 +154,8 @@ def read(self, length=None):
154154
Returns:
155155
bytes: file content.
156156
"""
157+
if length is not None and length <= 0:
158+
return b""
157159
result = bytearray()
158160
sector = 0
159161
while sector < MAX_SECTORS:

0 commit comments

Comments
 (0)