[New-bugs-announce] [issue35474] mimetypes.guess_all_extensions potentially mutates list
Ryan McCampbell
report at bugs.python.org
Wed Dec 12 14:06:57 EST 2018
New submission from Ryan McCampbell <rmccampbell7 at gmail.com>:
The mimetypes.guess_all_extensions function is defined as:
def guess_all_extensions(self, type, strict=True):
type = type.lower()
extensions = self.types_map_inv[True].get(type, [])
if not strict:
for ext in self.types_map_inv[False].get(type, []):
if ext not in extensions:
extensions.append(ext)
return extensions
If any mime type exists in both the strict and non-strict types_map_inv and it is called with strict=False, then it will modify the strict list in-place which effects future calls even with strict=True. While this doesn't manifest as an error for me because the dictionaries are non-overlapping, it is a potential error; it is also vulnerable to people accidentally modifying the returned list. The list should be copied after the first lookup.
----------
components: Library (Lib)
messages: 331715
nosy: rmccampbell7
priority: normal
severity: normal
status: open
title: mimetypes.guess_all_extensions potentially mutates list
type: behavior
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35474>
_______________________________________
More information about the New-bugs-announce
mailing list