
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2013-06-27 22:01 byjwilk, last changed2022-04-11 14:57 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| testcase.mo | jwilk,2013-06-27 22:01 | |||
| testcase.py | jwilk,2013-06-27 22:01 | |||
| 18317_gettext.patch | christian.heimes,2013-06-28 08:48 | review | ||
| 18317_gettext2.patch | christian.heimes,2013-06-28 14:57 | review | ||
| Messages (9) | |||
|---|---|---|---|
| msg191963 -(view) | Author: Jakub Wilk (jwilk) | Date: 2013-06-27 22:01 | |
It is possible to craft a MO file with Plural-Forms taking arbitrary amounts of CPU and memory to evaluate. A test case is attached.I realize that opening unstrusted MO files is a rather unusual use case, but the module already contains some code to protect againt malicious Plural-Forms, so I thought you might want to fix this problem as well. | |||
| msg191968 -(view) | Author: Christian Heimes (christian.heimes)*![]() | Date: 2013-06-27 23:01 | |
Thanks,can you please provide the PO file, too? Or did you construct the MO file manually? | |||
| msg191969 -(view) | Author: Christian Heimes (christian.heimes)*![]() | Date: 2013-06-27 23:10 | |
Ah, I see what you are doing. Nice catch!Plural-Forms: nplurals=0; plural=42**42**42;The plural form gets parsed by gettext.c2py() and eventually turned into a lambda that executes int(42**42**42). Perhaps a custom AST visitor could be used to filter out dangerous ops and limit the amount of ops to a sane amount? | |||
| msg191972 -(view) | Author: Benjamin Peterson (benjamin.peterson)*![]() | Date: 2013-06-28 00:41 | |
Why do we have "support" for untrusted MO files? | |||
| msg191980 -(view) | Author: Antoine Pitrou (pitrou)*![]() | Date: 2013-06-28 08:10 | |
I would rather ask: why do we eval() MO files? | |||
| msg191981 -(view) | Author: Christian Heimes (christian.heimes)*![]() | Date: 2013-06-28 08:48 | |
We don't eval() the whole MO file. It's just the pluralization formula,http://www.gnu.org/software/gettext/manual/gettext.html#index-nplurals_0040r_007b_002c-in-a-PO-file-header_007d-1093The patch uses ast.NodeVisitor to look for dangerous code. | |||
| msg191983 -(view) | Author: Jakub Wilk (jwilk) | Date: 2013-06-28 09:27 | |
Making token filtering more thorough may be simpler that going through AST.I think Python should accept all the operators that GNU gettext accepts:http://git.savannah.gnu.org/cgit/gettext.git/tree/gettext-runtime/intl/plural.y?id=v0.18.2.1#n132 | |||
| msg191995 -(view) | Author: Christian Heimes (christian.heimes)*![]() | Date: 2013-06-28 14:57 | |
Thanks for the link plural.y! I was looking for a C file, not a YACC file.The AST approach has advantages over tokenizing. The tokenizer returns just symbols but the AST has also context information. It makes it much easier to distinguish between unary - and binary -. Gettext supports substraction but doesn't allow negative numbers.Python's gettext is not as strict as GNU gettext. For 3.4 I like to forbid oct and hex numbers, too. | |||
| msg280338 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2016-11-08 19:32 | |
The DoS as well as other flaws is fixed inissue28563 by implementing a complete parser for GNU gettext plural form expressions. | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:47 | admin | set | github: 62517 |
| 2016-11-08 19:32:58 | serhiy.storchaka | set | status: open -> closed superseder:Arbitrary code execution in gettext.c2py nosy: +serhiy.storchaka messages: +msg280338 resolution: fixed stage: test needed -> resolved |
| 2016-09-08 23:44:11 | christian.heimes | set | versions: + Python 3.5, Python 3.6, Python 3.7, - Python 3.2, Python 3.3 |
| 2013-06-28 14:57:52 | christian.heimes | set | files: +18317_gettext2.patch messages: +msg191995 |
| 2013-06-28 09:27:23 | jwilk | set | messages: +msg191983 |
| 2013-06-28 08:48:11 | christian.heimes | set | files: +18317_gettext.patch keywords: +patch messages: +msg191981 |
| 2013-06-28 08:10:35 | pitrou | set | messages: +msg191980 |
| 2013-06-28 00:41:41 | benjamin.peterson | set | nosy: +benjamin.peterson messages: +msg191972 |
| 2013-06-27 23:10:57 | christian.heimes | set | nosy: +barry, -loewis messages: +msg191969 |
| 2013-06-27 23:02:46 | christian.heimes | set | nosy: +loewis,pitrou |
| 2013-06-27 23:01:28 | christian.heimes | set | versions: + Python 2.7, Python 3.2, Python 3.3, Python 3.4 nosy: +christian.heimes messages: +msg191968 stage: test needed |
| 2013-06-27 22:01:32 | jwilk | set | files: +testcase.py |
| 2013-06-27 22:01:26 | jwilk | create | |