From c68b6aaec8b08caf682ebb7c95f94ddf49a6b66c Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 23 Apr 2011 00:41:19 +0200 Subject: [PATCH] Issue #9319: Fix a crash on parsing a Python source code without encoding cookie and not valid in UTF-8: use "" as the filename instead of reading from NULL. --- Lib/test/test_imp.py | 3 +++ Parser/tokenizer.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py index d745ae9cc30..6f5b06aa1b1 100644 --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -170,6 +170,9 @@ class ImportTests(unittest.TestCase): support.unlink(init_file_name + ext) support.rmtree(test_package_name) + def test_issue9319(self): + imp.find_module("test/badsyntax_pep3120") + class ReloadTests(unittest.TestCase): diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 3f6be2f640e..5ba12a409d4 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -586,7 +586,10 @@ decoding_fgets(char *s, int size, struct tok_state *tok) if (badchar) { /* Need to add 1 to the line number, since this line has not been counted, yet. */ - filename = PyUnicode_DecodeFSDefault(tok->filename); + if (tok->filename != NULL) + filename = PyUnicode_DecodeFSDefault(tok->filename); + else + filename = PyUnicode_FromString(""); if (filename != NULL) { PyErr_Format(PyExc_SyntaxError, "Non-UTF-8 code starting with '\\x%.2x' "