summaryrefslogtreecommitdiffstats
path: root/Lib/gettext.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-10-28 19:17:51 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-10-28 19:17:51 (GMT)
commitbe8d06f5234ace688520bfea9139e68214788910 (patch)
treef478b190be5b947c2ccad48bf148a657a52a8267 /Lib/gettext.py
parentb7374d0271765f0abeb92f8d87b0ce9b0c2be3df (diff)
downloadcpython-be8d06f5234ace688520bfea9139e68214788910.zip
cpython-be8d06f5234ace688520bfea9139e68214788910.tar.gz
cpython-be8d06f5234ace688520bfea9139e68214788910.tar.bz2
Issue #18216: gettext now raises an error when a .mo file has an unsupported major version number. Patch by Aaron Hill.
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 05d9c1e..15378bc 100644
--- a/Lib/gettext.py
+++ b/Lib/gettext.py
@@ -225,6 +225,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
@@ -245,6 +252,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):