summaryrefslogtreecommitdiff
path: root/Lib/gettext.py
diff options
context:
space:
mode:
authorAndrew Kuchling <amk@amk.ca>2015-04-14 10:35:43 -0400
committerAndrew Kuchling <amk@amk.ca>2015-04-14 10:35:43 -0400
commit3b3863c2d496f01845eda76ccf6401458714397e (patch)
tree14af5692bc33ffc3a589478b03e33e597ce17166 /Lib/gettext.py
parentb6b4ba499008572740b20b22481074263fb4e5d7 (diff)
parentda4c26c69f751f7c0207b009b2372bdc12c08bba (diff)
downloadcpython-3b3863c2d496f01845eda76ccf6401458714397e.tar.gz
Merge from 3.4
Diffstat (limited to 'Lib/gettext.py')
-rw-r--r--Lib/gettext.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/gettext.py b/Lib/gettext.py
index 8caf1d1227..101378fefa 100644
--- a/Lib/gettext.py
+++ b/Lib/gettext.py
@@ -227,6 +227,13 @@ class GNUTranslations(NullTranslations):
LE_MAGIC = 0x950412de
BE_MAGIC = 0xde120495
+ # Acceptable .mo versions
+ VERSIONS = (0, 1)
+
+ def _get_versions(self, version):
+ """Returns a tuple of major version, minor version"""
+ return (version >> 16, version & 0xffff)
+
def _parse(self, fp):
"""Override this method to support alternative .mo formats."""
unpack = struct.unpack
@@ -247,6 +254,12 @@ class GNUTranslations(NullTranslations):
ii = '>II'
else:
raise OSError(0, 'Bad magic number', filename)
+
+ major_version, minor_version = self._get_versions(version)
+
+ if major_version not in self.VERSIONS:
+ raise OSError(0, 'Bad version number ' + str(major_version), filename)
+
# Now put all messages from the .mo file buffer into the catalog
# dictionary.
for i in range(0, msgcount):