
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2017-08-28 08:44 byOren Milman, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 3226 | merged | Oren Milman,2017-08-28 09:22 | |
| PR 3243 | merged | Oren Milman,2017-08-30 10:29 | |
| Messages (9) | |||
|---|---|---|---|
| msg300944 -(view) | Author: Oren Milman (Oren Milman)* | Date: 2017-08-28 08:44 | |
on Windows, assuming the file 'foo.zip' exists, the following would cause anassertion failure inModules/zipimport.c in zipimport_zipimporter_get_data_impl():import zipimportclass BadStr(str): def replace(self, old, new): return 42zipimport.zipimporter('foo.zip').get_data(BadStr('bar'))this is because zipimport_zipimporter_get_data_impl() assumes thatBadStr('bar').replace('/', '\\') is a string. | |||
| msg300962 -(view) | Author: Brett Cannon (brett.cannon)*![]() | Date: 2017-08-28 19:45 | |
I don't think this is a bad thing. This is duck-typing at work to be flexible where the type doesn't really matter, just the provided interface. If someone happens to provide an object that doesn't do the right thing then that's their fault for using the wrong object and the resulting exception that will occur from a bad path is acceptable.I appreciate the work to do a PR, Oren, but I'm closing this issue as "rejected". (And if it makes you feel any better, you helped find a bug in the Bedevere bot. :) . | |||
| msg300963 -(view) | Author: Oren Milman (Oren Milman)* | Date: 2017-08-28 19:57 | |
I understand that our goal is to make Python better, not to make me happier :)anyway, I haven't checked, but I am quite sure that similar code mightcrash the interpreter on a release build of Python.(just wanted to clarify that, as you used the term 'exception'.) | |||
| msg300965 -(view) | Author: Brett Cannon (brett.cannon)*![]() | Date: 2017-08-28 20:38 | |
If it will crash the interpreter then that's different. If that turns out to be the case then please come back here and we can rework the issue and PR to prevent that by being better about checking return values or resulting exception cases. | |||
| msg300966 -(view) | Author: Oren Milman (Oren Milman)* | Date: 2017-08-28 20:58 | |
just checked, and indeed on my Windows 10 the original code I posted herecrashes the interpreter.The patch in the PR undermines duck-typing, and that's why I added a commentthere, stating I wasn't sure about the patch.an alternate solution would be to simply check whether the return value ofpathname.replace('/', '\') is a str.do you think I would update the PR to do that? | |||
| msg300967 -(view) | Author: Brett Cannon (brett.cannon)*![]() | Date: 2017-08-28 22:00 | |
Could you paste in what the crash looks like? E.g. is it a segfault, SystemError, etc.?And you can tweak the PR or just open a new one if you would rather that fixes the crash itself without taking away duck typing. | |||
| msg300972 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2017-08-29 04:10 | |
Oren already fixed several similar problems and he is aware of difference between a crash and an exception.The problem is Windows specific. The current code uses Unicode C API with the result of calling the replace method. This can cause a segfault (or may be an assertion failure in debug build).The proposed solution LGTM. It undermines duck-typing, but I think this doesn't break any existing code. The duck-typing was not intentional and is Windows-only. | |||
| msg300995 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2017-08-29 17:40 | |
New changeset631fdee6e61b4ba8ce800f827fecdd536bfb04f3 by Serhiy Storchaka (Oren Milman) in branch 'master':bpo-31291: Fixed an assertion failure in zipimport.zipimporter.get_data() (#3226)https://github.com/python/cpython/commit/631fdee6e61b4ba8ce800f827fecdd536bfb04f3 | |||
| msg301021 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2017-08-30 11:08 | |
New changeset095a421b1606ee27e00a5d9d253b05a9f0cfadb8 by Serhiy Storchaka (Oren Milman) in branch '3.6':[3.6]bpo-31291: Fixed an assertion failure in zipimport.zipimporter.get_data() (GH-3226) (#3243)https://github.com/python/cpython/commit/095a421b1606ee27e00a5d9d253b05a9f0cfadb8 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:51 | admin | set | github: 75472 |
| 2017-08-30 11:09:04 | serhiy.storchaka | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2017-08-30 11:08:45 | serhiy.storchaka | set | messages: +msg301021 |
| 2017-08-30 10:29:45 | Oren Milman | set | pull_requests: +pull_request3287 |
| 2017-08-29 17:40:17 | serhiy.storchaka | set | messages: +msg300995 |
| 2017-08-29 04:10:45 | serhiy.storchaka | set | versions: + Python 3.6 nosy: +serhiy.storchaka messages: +msg300972 components: + Extension Modules, - Interpreter Core stage: patch review |
| 2017-08-28 22:00:49 | brett.cannon | set | title: an assertion failure in zipimport.zipimporter.get_data() -> zipimport.zipimporter.get_data() crashes when path.replace() returns a non-str |
| 2017-08-28 22:00:24 | brett.cannon | set | status: closed -> open resolution: rejected -> (no value) stage: resolved -> (no value) |
| 2017-08-28 22:00:14 | brett.cannon | set | messages: +msg300967 |
| 2017-08-28 20:58:15 | Oren Milman | set | messages: +msg300966 |
| 2017-08-28 20:38:29 | brett.cannon | set | messages: +msg300965 |
| 2017-08-28 19:57:03 | Oren Milman | set | messages: +msg300963 |
| 2017-08-28 19:45:48 | brett.cannon | set | status: open -> closed nosy: +brett.cannon,twouters messages: +msg300962 resolution: rejected stage: resolved |
| 2017-08-28 09:22:17 | Oren Milman | set | pull_requests: +pull_request3269 |
| 2017-08-28 08:44:26 | Oren Milman | create | |