New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gettext doesn't check MO versions #62416
Comments
The MO file format specification[0] reads: As a test-case I attached a MO file with a bogus major revision number. msgunfmt correcly rejects such a file: $ msgunfmt messages.mo
msgunfmt: file "messages.mo" is not in GNU .mo format Yet Python opens it happily: >>> import gettext
>>> t = gettext.GNUTranslations(open("messages.mo", "rb"))
>>> t.gettext("foo")
'bar' [0] http://www.gnu.org/software/gettext/manual/html_node/MO-Files.html |
@jakub does this apply to all Python versions and OSes? |
I believe so, yes. |
The patch hardcodes 5 as version number in the exception message. The specifiction also says that "an unexpected minor revision number means that the file can be read but will not reveal its full contents, when parsed by a program that supports only smaller minor revision numbers". So I think a reasonable thing to do is to accept MO files with an expected major revision but an unexpected minor revision. |
That sounds good. Should a warning be thrown for an unexpected minor revision? |
Does anyone have any thoughts about throwing a warning for an unexpected minor revision? |
The linked docs say: """an unexpected minor revision number means that the file can be read but will not reveal its full contents, when parsed by a program that supports only smaller minor revision numbers""". Unless there an important piece of contents that can be missed, I would say a warning is more of a distraction here. |
Okay, then. I'll just leave it out. |
I've added a second patch, which properly distinguishes between major and minor revisions, and updates the docs to account for the new behavior. |
Is there anything that needs to be changed? |
Aaron, the patch looks fine, I'm going to commit it. |
New changeset 3b26a0983a3c by Antoine Pitrou in branch 'default': |
I've pushed it to 3.5 only. I don't think it's worth risking compatibility breakage in bugfix branches. Thank you for your contribution! |
Awesome! Thanks! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: