Skip to content

Don't crash on non-UTF-8 bytes in the map file - #3

Open
munzzyy wants to merge 1 commit into
flipperdevices:devfrom
munzzyy:fix-map-encoding
Open

Don't crash on non-UTF-8 bytes in the map file#3
munzzyy wants to merge 1 commit into
flipperdevices:devfrom
munzzyy:fix-map-encoding

Conversation

@munzzyy

@munzzyy munzzyy commented Jul 27, 2026

Copy link
Copy Markdown

Fixes #2.

parse_sections() opens the map file with the platform default encoding and no error handling, so one non-UTF-8 byte anywhere in the file kills the parse. Linker maps quote build paths verbatim, so this happens as soon as a path contains a character that isn't ASCII — which is what the reporter in #2 hit on Fedora.

Reproduced with a map file that is otherwise well formed, with a single 0xe9 byte inside a path in a .text entry:

  File "map_parser.py", line 62, in parse_sections
    line = file.readline()
  File "<frozen codecs>", line 325, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 243: invalid continuation byte

Reading with errors='replace' parses the same file cleanly. Only the offending byte in the path degrades to U+FFFD; every address and size in the output is unchanged, since those are plain ASCII hex on their own columns.

Second, smaller thing in the same function: the "memory configuration not found" path raises using input_file, which isn't a parameter of parse_sections — it only exists as a module-level name when the file is run as a script. Import the function and call it directly on a map with no Memory Configuration header and you get NameError: name 'input_file' is not defined instead of the intended message. Switched it to the function's own file_name argument, and dropped the missing space after "the".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

failed on fedora 40 server.

1 participant