mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-28 04:48:16 +00:00
crit: Avoid full exception trace when meeting unknown magic in image (v2)
Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Acked-by: Andrew Vagin <avagin@virtuozzo.com>
This commit is contained in:
parent
5a9fe81b75
commit
dbda403b8d
7
crit
7
crit
@ -20,7 +20,14 @@ def outf(opts):
|
|||||||
|
|
||||||
def decode(opts):
|
def decode(opts):
|
||||||
indent = None
|
indent = None
|
||||||
|
|
||||||
|
try:
|
||||||
img = pycriu.images.load(inf(opts), opts['pretty'])
|
img = pycriu.images.load(inf(opts), opts['pretty'])
|
||||||
|
except pycriu.images.MagicException as exc:
|
||||||
|
print >>sys.stderr, "Unknown magic %#x.\n"\
|
||||||
|
"Maybe you are feeding me an image with "\
|
||||||
|
"raw data(i.e. pages.img)?" % exc.magic
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if opts['pretty']:
|
if opts['pretty']:
|
||||||
indent = 4
|
indent = 4
|
||||||
|
@ -50,6 +50,10 @@ import pb2dict
|
|||||||
import magic
|
import magic
|
||||||
from pb import *
|
from pb import *
|
||||||
|
|
||||||
|
class MagicException(Exception):
|
||||||
|
def __init__(self, magic):
|
||||||
|
self.magic = magic
|
||||||
|
|
||||||
# Generic class to handle loading/dumping criu images entries from/to bin
|
# Generic class to handle loading/dumping criu images entries from/to bin
|
||||||
# format to/from dict(json).
|
# format to/from dict(json).
|
||||||
class entry_handler:
|
class entry_handler:
|
||||||
@ -300,9 +304,7 @@ def load(f, pretty = False):
|
|||||||
try:
|
try:
|
||||||
m = magic.by_val[img_magic]
|
m = magic.by_val[img_magic]
|
||||||
except:
|
except:
|
||||||
raise Exception("Unknown magic "+str(img_magic)+".\n"\
|
raise MagicException(img_magic)
|
||||||
"Maybe you are feeding me an image with "\
|
|
||||||
"raw data(i.e. pages.img)?")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
handler = handlers[m]
|
handler = handlers[m]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user