[Concept,02/15] patman: Handle invalid characters in patch files

Message ID 20250819193918.874215-3-sjg@u-boot.org
State New
Headers
Series test: Improvements to make check et al |

Commit Message

Simon Glass Aug. 19, 2025, 7:38 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

In some cases latin1 encoding may be used in source files. If
'high-ascii' are used, patman may report an error:

   UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf3 in
      position 1051: invalid continuation byte

Fix this by replacing these characters. This may cause the patch to fail
to apply, but at least it can be checked.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/patman/patchstream.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/tools/patman/patchstream.py b/tools/patman/patchstream.py
index 45040877f8c..120004a3e0d 100644
--- a/tools/patman/patchstream.py
+++ b/tools/patman/patchstream.py
@@ -831,7 +831,7 @@  def fix_patch(backup_dir, fname, series, cmt, keep_change_id=False,
     fname = os.path.join(cwd or '', fname)
     handle, tmpname = tempfile.mkstemp()
     outfd = os.fdopen(handle, 'w', encoding='utf-8')
-    infd = open(fname, 'r', encoding='utf-8')
+    infd = open(fname, 'r', encoding='utf-8', errors='replace')
     pst = PatchStream(series, keep_change_id=keep_change_id,
                       insert_base_commit=insert_base_commit)
     pst.commit = cmt