|
1 |
| -From fca73313b77d2c8ea32db8b21858745500c334ec Mon Sep 17 00:00:00 2001 |
2 |
| -From: Jan-Michael Brummer <jan [email protected]> |
3 |
| -Date: Tue, 26 Mar 2024 10:27:48 +0100 |
4 |
| -Subject: [PATCH] Fix composite key computation for BytesIO |
| 1 | +From c67b8cfdd51d60b8ef479bfbdf064f54fe593ae8 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jan-Michael Brummer <jan [email protected]> |
| 3 | +Date: Tue, 9 Apr 2024 21:58:09 +0200 |
| 4 | +Subject: [PATCH] Fix composite key computation for BytesIO (#388) |
5 | 5 |
|
6 | 6 | In case a keyfile as BytesIO has been read before, the
|
7 | 7 | next read will be empty. We need to ensure that we
|
8 | 8 | are reading the data from the beginning.
|
9 | 9 |
|
10 | 10 | Add seek to start to fix it.
|
| 11 | + |
| 12 | +Co-authored-by: Jan-Michael Brummer < [email protected]> |
11 | 13 | ---
|
12 |
| - pykeepass/kdbx_parsing/common.py | 9 ++++++++- |
13 |
| - 1 file changed, 8 insertions(+), 1 deletion(-) |
| 14 | + pykeepass/kdbx_parsing/common.py | 6 ++++-- |
| 15 | + 1 file changed, 4 insertions(+), 2 deletions(-) |
14 | 16 |
|
15 | 17 | diff --git a/pykeepass/kdbx_parsing/common.py b/pykeepass/kdbx_parsing/common.py
|
16 |
| -index 3973f61..1865bb4 100644 |
| 18 | +index 3973f61..94eb58b 100644 |
17 | 19 | --- a/pykeepass/kdbx_parsing/common.py
|
18 | 20 | +++ b/pykeepass/kdbx_parsing/common.py
|
19 |
| -@@ -13,6 +13,7 @@ import unicodedata |
| 21 | +@@ -9,11 +9,11 @@ from lxml import etree |
| 22 | + from copy import deepcopy |
| 23 | + import base64 |
| 24 | + from binascii import Error as BinasciiError |
| 25 | ++import io |
| 26 | + import unicodedata |
20 | 27 | import zlib
|
21 | 28 | import re
|
22 | 29 | import codecs
|
23 |
| -+import io |
24 |
| - from io import BytesIO |
| 30 | +-from io import BytesIO |
25 | 31 | from collections import OrderedDict
|
26 | 32 | import logging
|
27 |
| -@@ -116,7 +117,13 @@ def compute_key_composite(password=None, keyfile=None): |
28 |
| - password_composite = b'' |
| 33 | + |
| 34 | +@@ -117,6 +117,8 @@ def compute_key_composite(password=None, keyfile=None): |
29 | 35 | # hash the keyfile
|
30 | 36 | if keyfile:
|
31 |
| -- if hasattr(keyfile, "read"): |
32 |
| -+ if ( |
33 |
| -+ isinstance(keyfile, io.BufferedIOBase) |
34 |
| -+ or isinstance(keyfile, io.TextIOBase) |
35 |
| -+ or isinstance(keyfile, io.RawIOBase) |
36 |
| -+ ): |
37 |
| -+ if keyfile.seekable(): |
| 37 | + if hasattr(keyfile, "read"): |
| 38 | ++ if hasattr(keyfile, "seekable") and keyfile.seekable(): |
38 | 39 | + keyfile.seek(0)
|
39 | 40 | keyfile_bytes = keyfile.read()
|
40 | 41 | else:
|
41 | 42 | with open(keyfile, 'rb') as f:
|
| 43 | +@@ -183,7 +185,7 @@ class XML(Adapter): |
| 44 | + |
| 45 | + def _decode(self, data, con, path): |
| 46 | + parser = etree.XMLParser(remove_blank_text=True) |
| 47 | +- return etree.parse(BytesIO(data), parser) |
| 48 | ++ return etree.parse(io.BytesIO(data), parser) |
| 49 | + |
| 50 | + def _encode(self, tree, con, path): |
| 51 | + return etree.tostring(tree) |
42 | 52 | --
|
43 | 53 | 2.44.0
|
44 | 54 |
|
0 commit comments