Don't crash on non-UTF-8 bytes in the map file - #3
Open
munzzyy wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
0xe9byte inside a path in a.textentry: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 ofparse_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 noMemory Configurationheader and you getNameError: name 'input_file' is not definedinstead of the intended message. Switched it to the function's ownfile_nameargument, and dropped the missing space after "the".