-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
gh-119342: Fix OOM vulnerability in plistlib #119343
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -508,12 +508,31 @@ def _get_size(self, tokenL): | |
|
|
||
| return tokenL | ||
|
|
||
| def _read(self, size): | ||
| if 0: | ||
| data = self._fp.read(size) | ||
| if len(data) != size: | ||
| raise InvalidFileException | ||
| return data | ||
| cursize = min(size, 1 << 20) | ||
|
||
| data = self._fp.read(cursize) | ||
| while True: | ||
| if len(data) != cursize: | ||
| raise InvalidFileException | ||
| if cursize == size: | ||
| return data | ||
| delta = min(cursize, size - cursize) | ||
| data += self._fp.read(delta) | ||
| cursize += delta | ||
|
|
||
| def _read_ints(self, n, size): | ||
| data = self._fp.read(size * n) | ||
| data = self._read(size * n) | ||
| #print('XXX', n, size) | ||
| #assert n < 100 | ||
serhiy-storchaka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if size in _BINARY_FORMAT: | ||
| return struct.unpack(f'>{n}{_BINARY_FORMAT[size]}', data) | ||
| else: | ||
| if not size or len(data) != size * n: | ||
| if not size: | ||
| raise InvalidFileException() | ||
| return tuple(int.from_bytes(data[i: i + size], 'big') | ||
| for i in range(0, size * n, size)) | ||
|
|
@@ -573,22 +592,16 @@ def _read_object(self, ref): | |
|
|
||
| elif tokenH == 0x40: # data | ||
| s = self._get_size(tokenL) | ||
| result = self._fp.read(s) | ||
| if len(result) != s: | ||
| raise InvalidFileException() | ||
| result = self._read(s) | ||
|
|
||
| elif tokenH == 0x50: # ascii string | ||
| s = self._get_size(tokenL) | ||
| data = self._fp.read(s) | ||
| if len(data) != s: | ||
| raise InvalidFileException() | ||
| data = self._read(s) | ||
| result = data.decode('ascii') | ||
|
|
||
| elif tokenH == 0x60: # unicode string | ||
| s = self._get_size(tokenL) * 2 | ||
| data = self._fp.read(s) | ||
| if len(data) != s: | ||
| raise InvalidFileException() | ||
| data = self._read(s) | ||
| result = data.decode('utf-16be') | ||
|
|
||
| elif tokenH == 0x80: # UID | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix OOM vulnerability in :mod:`plistlib`, when reading a specially prepared | ||
| small Plist file could cause consuming an arbitrary amount of memory. |
Uh oh!
There was an error while loading. Please reload this page.