Matej Habrnal 66b169
From 8f26482402179dc64b9488be05ef9686922446ec Mon Sep 17 00:00:00 2001
Matej Habrnal 66b169
From: Jakub Filak <jfilak@redhat.com>
Matej Habrnal 66b169
Date: Fri, 24 Jul 2015 13:50:00 +0200
Matej Habrnal 66b169
Subject: [PATCH] vmcore: read vmcore by chunks
Matej Habrnal 66b169
Matej Habrnal 66b169
Reading vmcore by lines was not a good idea and the switch to Python 3
Matej Habrnal 66b169
makes it impossible because of the binary format of that file (the file
Matej Habrnal 66b169
does not contain only valid Unicode strings and that raises
Matej Habrnal 66b169
UnicodeDecodeError from the for statement).
Matej Habrnal 66b169
Matej Habrnal 66b169
Signed-off-by: Jakub Filak <jfilak@redhat.com>
Matej Habrnal 66b169
---
Matej Habrnal 66b169
 src/hooks/abrt_harvest_vmcore.py.in | 9 ++++++---
Matej Habrnal 66b169
 1 file changed, 6 insertions(+), 3 deletions(-)
Matej Habrnal 66b169
Matej Habrnal 66b169
diff --git a/src/hooks/abrt_harvest_vmcore.py.in b/src/hooks/abrt_harvest_vmcore.py.in
Matej Habrnal 66b169
index c5e7d53..61a6e57 100644
Matej Habrnal 66b169
--- a/src/hooks/abrt_harvest_vmcore.py.in
Matej Habrnal 66b169
+++ b/src/hooks/abrt_harvest_vmcore.py.in
Matej Habrnal 66b169
@@ -214,9 +214,12 @@ def harvest_vmcore():
Matej Habrnal 66b169
         hashobj = hashlib.sha1()
Matej Habrnal 66b169
         # Iterate over the file a line at a time in order to not load the whole
Matej Habrnal 66b169
         # vmcore file
Matej Habrnal 66b169
-        with open(os.path.join(f_full, 'vmcore'), 'r') as corefile:
Matej Habrnal 66b169
-            for line in corefile:
Matej Habrnal 66b169
-                hashobj.update(line)
Matej Habrnal 66b169
+        with open(os.path.join(f_full, 'vmcore'), 'rb') as corefile:
Matej Habrnal 66b169
+            while True:
Matej Habrnal 66b169
+                chunk = corefile.read(8192)
Matej Habrnal 66b169
+                if not chunk:
Matej Habrnal 66b169
+                    break
Matej Habrnal 66b169
+                hashobj.update(chunk)
Matej Habrnal 66b169
 
Matej Habrnal 66b169
         dd = create_abrtd_info(destdirnew, hashobj.hexdigest())
Matej Habrnal 66b169
         if dd is None:
Matej Habrnal 66b169
-- 
Matej Habrnal 66b169
2.4.6
Matej Habrnal 66b169