Skip to content

Commit 5e70cc6

Browse files
authored
Avoid StackOverflowException in mimetypes (#1183)
1 parent 03e9bde commit 5e70cc6

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

Src/IronPythonTest/Cases/CPythonCasesManifest.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,6 @@ IsolationLevel=PROCESS # Also weakref failures; https://github.com/IronLanguages
617617
[CPython.test_metaclass]
618618
Ignore=true
619619

620-
[CPython.test_mimetypes]
621-
Ignore=true
622-
Reason=StackOverflowException - https://github.com/IronLanguages/ironpython2/issues/182
623-
624620
[CPython.test_mmap]
625621
RunCondition=NOT $(IS_POSIX)
626622
IsolationLevel=PROCESS

Src/StdLib/Lib/mimetypes.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,19 +252,21 @@ def enum_types(mimedb):
252252

253253
with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
254254
for subkeyname in enum_types(hkcr):
255-
try:
256-
with _winreg.OpenKey(hkcr, subkeyname) as subkey:
257-
# Only check file extensions
258-
if not subkeyname.startswith("."):
259-
continue
255+
# ironpython: code modified to avoid StackOverflowException - https://github.com/IronLanguages/ironpython3/issues/1182
256+
with _winreg.OpenKey(hkcr, subkeyname) as subkey:
257+
# Only check file extensions
258+
if not subkeyname.startswith("."):
259+
continue
260+
try:
260261
# raises EnvironmentError if no 'Content Type' value
261262
mimetype, datatype = _winreg.QueryValueEx(
262263
subkey, 'Content Type')
264+
except EnvironmentError:
265+
pass
266+
else:
263267
if datatype != _winreg.REG_SZ:
264268
continue
265269
self.add_type(mimetype, subkeyname, strict)
266-
except EnvironmentError:
267-
continue
268270

269271
def guess_type(url, strict=True):
270272
"""Guess the type of a file based on its URL.

0 commit comments

Comments
 (0)