mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	Issue #9319: Fix a crash on parsing a Python source code without encoding
cookie and not valid in UTF-8: use "<file>" as the filename instead of reading from NULL.
This commit is contained in:
		
							parent
							
								
									5569e9b150
								
							
						
					
					
						commit
						c68b6aaec8
					
				
					 2 changed files with 7 additions and 1 deletions
				
			
		| 
						 | 
					@ -170,6 +170,9 @@ def test_issue5604(self):
 | 
				
			||||||
                support.unlink(init_file_name + ext)
 | 
					                support.unlink(init_file_name + ext)
 | 
				
			||||||
            support.rmtree(test_package_name)
 | 
					            support.rmtree(test_package_name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_issue9319(self):
 | 
				
			||||||
 | 
					        imp.find_module("test/badsyntax_pep3120")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ReloadTests(unittest.TestCase):
 | 
					class ReloadTests(unittest.TestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -586,7 +586,10 @@ decoding_fgets(char *s, int size, struct tok_state *tok)
 | 
				
			||||||
    if (badchar) {
 | 
					    if (badchar) {
 | 
				
			||||||
        /* Need to add 1 to the line number, since this line
 | 
					        /* Need to add 1 to the line number, since this line
 | 
				
			||||||
           has not been counted, yet.  */
 | 
					           has not been counted, yet.  */
 | 
				
			||||||
        filename = PyUnicode_DecodeFSDefault(tok->filename);
 | 
					        if (tok->filename != NULL)
 | 
				
			||||||
 | 
					            filename = PyUnicode_DecodeFSDefault(tok->filename);
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					            filename = PyUnicode_FromString("<file>");
 | 
				
			||||||
        if (filename != NULL) {
 | 
					        if (filename != NULL) {
 | 
				
			||||||
            PyErr_Format(PyExc_SyntaxError,
 | 
					            PyErr_Format(PyExc_SyntaxError,
 | 
				
			||||||
                    "Non-UTF-8 code starting with '\\x%.2x' "
 | 
					                    "Non-UTF-8 code starting with '\\x%.2x' "
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue