Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue15207] mimetypes.read_windows_registry() uses the wrong regkey, creates wrong mappings

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Jun 27, 2012, 9:03 AM

Post #1 of 6 (85 views)
Permalink
[issue15207] mimetypes.read_windows_registry() uses the wrong regkey, creates wrong mappings

New submission from Dave Chambers <dlchambers [at] aol>:

The current mimetypes.read_windows_registry() enums the values under HKCR\MIME\Database\Content Type
However, this is the key for mimetype to extension lookups, NOT for extension to mimetype lookups.
As a result, when >1 MIME types are mapped to a particular extension, the last-found entry is used.
For example, both "image/png" and "image/x-png" map to the ".png" file extension.
Unfortunately, what happens is this code finds "image/png", then later finds "image/x-png" and this steals the ".png" extension.


The solution is to use the correct regkey, which is the HKCR root.
This is the correct location for extension-to-mimetype lookups.
What we should do is enum the HKCR root, find all subkeys that start with a dot (i.e. file extensions), then inspect those for a 'Content Type' value.


The attached ZIP contains:
mimetype_flaw_demo.py - this demonstrates the error (due to wrong regkey) and my fix (uses the correct regkey)
mimetypes_fixed.py - My suggested fix to the standard mimetypes.py module.

----------
components: Windows
files: mimetype_flaw_demo.zip
messages: 164167
nosy: dlchambers
priority: normal
severity: normal
status: open
title: mimetypes.read_windows_registry() uses the wrong regkey, creates wrong mappings
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file26180/mimetype_flaw_demo.zip

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15207>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 27, 2012, 10:39 AM

Post #2 of 6 (73 views)
Permalink
[issue15207] mimetypes.read_windows_registry() uses the wrong regkey, creates wrong mappings [In reply to]

R. David Murray <rdmurray [at] bitdance> added the comment:

Thanks for working on this. Could you please post the fix as a patch file? If you don't have mercurial, you can generate the diff on windows using the python diff module (scripts/diff.py -u <yourfile> <origfile>). Actually, I'm not sure exactly where diff is in the windows install, but I know it is there.

Do you know if image/x-png and image/png are included in the registry on all windows versions? If so we could use that key for a unit test.

----------
components: +email
nosy: +barry, r.david.murray
stage: -> needs patch
versions: +Python 3.2, Python 3.3

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15207>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 27, 2012, 10:54 AM

Post #3 of 6 (73 views)
Permalink
[issue15207] mimetypes.read_windows_registry() uses the wrong regkey, creates wrong mappings [In reply to]

Dave Chambers <dlchambers [at] aol> added the comment:

My first diff file... I hope I did it right :)

----------
keywords: +patch
Added file: http://bugs.python.org/file26181/mimetypes.py.diff

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15207>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 27, 2012, 11:06 AM

Post #4 of 6 (75 views)
Permalink
[issue15207] mimetypes.read_windows_registry() uses the wrong regkey, creates wrong mappings [In reply to]

Dave Chambers <dlchambers [at] aol> added the comment:

I added a diff file to the bug.
Dunno if that's the same as a patch file, or how to create a patchfile if it's not.

>Do you know if image/x-png and image/png are included in the registry on all
> windows versions?

I think your question is reversed, in the same way that the code was reversed.
You're not looking for image/png and/or image/x-png. You're looking for .png in order to retrieve its mimetype (aka Content Type).
While nothing is 100% certain on Windows :), I'm quite confident that every copy will have an HKCR\.png regkey, and that regkey will have a Content Type value, and that value's setting will be the appropriate mometype, which I'd expect to be image/png.

I was kinda surprised to find this bug as it's so obvious
I started chasing it because Chrome kept complaining that pngs were being served as image/x-png (by CherryPy).
There are other bugs (eg: 15199, 10551) that my patch should fix.

-Dave

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15207>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 27, 2012, 12:30 PM

Post #5 of 6 (69 views)
Permalink
[issue15207] mimetypes.read_windows_registry() uses the wrong regkey, creates wrong mappings [In reply to]

R. David Murray <rdmurray [at] bitdance> added the comment:

Well, I had no involvement in the windows registry reading stuff, and it is relatively new. And, as issue 10551 indicates, a bit controversial. (issue 15199 is a different bug, in python's own internal table).

Can you run that diff again and use the '-u' flag? The -u (universal) format is the one we are used to working with. The one you posted still lets us read the changes, though, which is very helpful.

----------
nosy: +brian.curtin, tim.golden

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15207>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 27, 2012, 12:54 PM

Post #6 of 6 (69 views)
Permalink
[issue15207] mimetypes.read_windows_registry() uses the wrong regkey, creates wrong mappings [In reply to]

Changes by Dave Chambers <dlchambers [at] aol>:


Added file: http://bugs.python.org/file26185/mimetypes.py.diff.u

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15207>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.