New submission from Ryan McCampbell <rmccampbe...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue35474>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to