This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: compile of code with incorrect encoding yields MemoryError
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: atuining, mwh, nnorwitz, theller
Priority: normal Keywords:

Created on 2004-06-25 13:45 by atuining, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
thats-no-memory-error.diff mwh, 2004-08-07 21:33 one approach.
Messages (5)
msg21298 - (view) Author: Anthony Tuininga (atuining) * Date: 2004-06-25 13:45
The following code will fail in both Python 2.3 and
Python 2.4, raising a MemoryError exception, when run
on any platform except Windows:

compile("# -*- coding: mbcs -*-", "test.py", "exec")

This has been reproduced on the following platforms:

Linux x86
HP-UX
Solaris
Tru64 Unix

I realize this is an invalid encoding but it would be
nice if something other than MemoryError was raised!
msg21299 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2004-06-25 19:09
Logged In: YES 
user_id=11105

I assume the behaviour occurrs when an unknown encoding is
specified.  It can be reproduced on Windows:

compile("# -*- coding: xxx -*-", "test.py", "exec")

It should probably raise a SyntaxError, as trying to import
a module containing this encoding does.

The problem seems that when
PyParser_ParseStringFlagsFilename() calls
PyTokenizer_FromString(), and when the latter fails the
error is set to E_NOMEM.
msg21300 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2004-08-07 21:33
Logged In: YES 
user_id=6656

Here's a simple and seemingly effective patch.  I'm not sure
it's "the right thing", though.  The whole issue of whether
the parser should or should not set exceptions is a
frightful mess.
msg21301 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2005-10-03 05:00
Logged In: YES 
user_id=33168

Duplicate of #772896.  This has been fixed in CVS.  It's up
to Anthony whether it should be backported to 2.4 or not.
msg21302 - (view) Author: Anthony Tuininga (atuining) * Date: 2005-10-03 14:03
Logged In: YES 
user_id=619560

No need to backport -- the solution is quite simple. I was
simply reporting it so that it would eventually get fixed.
And it has, so I'm happy. :-)
History
Date User Action Args
2022-04-11 14:56:05adminsetgithub: 40451
2004-06-25 13:45:23atuiningcreate