psobot / keynote-parser

A packer/unpacker for Apple Keynote presentation files.
158 stars 17 forks source link

Key Error of "ID_NAME_MAP[message_info.type]" #46

Open Erimus-Koo opened 1 year ago

Erimus-Koo commented 1 year ago

Environments

Keynote: version 12.2.1 (7035.0.161) keynote-parser: 1.12.2.0 python: 3.10.9

Error message

Reading Index/CalculationEngine.iwa...:  61%|███████████████████████████████████████████████████████████▍                                      | 103/170 [00:00<00:00, 2282.54it/s]
Traceback (most recent call last):
  File "/Users/erimus/.pyenv/versions/3.10.9/envs/test/lib/python3.10/site-packages/keynote_parser/codec.py", line 195, in from_buffer
    klass = ID_NAME_MAP[message_info.type]
KeyError: 6383

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/erimus/.pyenv/versions/3.10.9/envs/test/lib/python3.10/site-packages/keynote_parser/codec.py", line 43, in from_buffer
    chunk, data = IWACompressedChunk.from_buffer(data, filename)
  File "/Users/erimus/.pyenv/versions/3.10.9/envs/test/lib/python3.10/site-packages/keynote_parser/codec.py", line 107, in from_buffer
    archive, data = IWAArchiveSegment.from_buffer(data, filename)
  File "/Users/erimus/.pyenv/versions/3.10.9/envs/test/lib/python3.10/site-packages/keynote_parser/codec.py", line 197, in from_buffer
    raise NotImplementedError(
NotImplementedError: Don't know how to parse Protobuf message type 6383

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/erimus/.pyenv/versions/3.10.9/envs/test/lib/python3.10/site-packages/keynote_parser/file_utils.py", line 230, in process
    process_file(filename, handle, sink, replacements, raw, on_replace)
  File "/Users/erimus/.pyenv/versions/3.10.9/envs/test/lib/python3.10/site-packages/keynote_parser/file_utils.py", line 175, in process_file
    file = IWAFile.from_buffer(contents, filename)
  File "/Users/erimus/.pyenv/versions/3.10.9/envs/test/lib/python3.10/site-packages/keynote_parser/codec.py", line 49, in from_buffer
    raise_from(ValueError("Failed to deserialize " + filename), e)
  File "/Users/erimus/.pyenv/versions/3.10.9/envs/test/lib/python3.10/site-packages/future/utils/__init__.py", line 403, in raise_from
    exec(execstr, myglobals, mylocals)
  File "<string>", line 1, in <module>
ValueError: Failed to deserialize Index/CalculationEngine.iwa

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/erimus/.pyenv/versions/test/bin/keynote-parser", line 8, in <module>
    sys.exit(main())
  File "/Users/erimus/.pyenv/versions/3.10.9/envs/test/lib/python3.10/site-packages/keynote_parser/command_line.py", line 121, in main
    args.func(**vars(args))
  File "/Users/erimus/.pyenv/versions/3.10.9/envs/test/lib/python3.10/site-packages/keynote_parser/command_line.py", line 25, in unpack_command
    process(input, output or input.replace('.key', ''), replacements=parse_replacements(**kwargs))
  File "/Users/erimus/.pyenv/versions/3.10.9/envs/test/lib/python3.10/site-packages/keynote_parser/file_utils.py", line 232, in process
    raise ValueError("Failed to process file %s due to: %s" % (filename, e))
ValueError: Failed to process file Index/CalculationEngine.iwa due to: Failed to deserialize Index/CalculationEngine.iw
Erimus-Koo commented 1 year ago

I've found out the problem page and output a "error_sample.key" file, and do you need it?

Erimus-Koo commented 1 year ago

The problems happened while some objects used(and error key):

Erimus-Koo commented 1 year ago

And there's another problem is, after once used the "replace" command, it looks like a codec error occurred. Here is the console:

    _file.filename = _file.filename.encode("cp437").decode("utf-8")
  File "/Users/erimus/.pyenv/versions/3.10.9/lib/python3.10/encodings/cp437.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 10-16: character maps to <undefined>
amasmiller commented 1 year ago

I am also seeing the error when parsing the identifier 6383, which appears to be the result of having a table in the file. Python 3.8.2, keynote-parser v1.12.2.0, Keynote v12.2.1.

Example .key file generating the error is attached (attached in .zip format because Github is cranky about .key files).

example.zip

amasmiller commented 1 year ago

I fixed the issues I was having by making a few modifications to codec.py and mapping.py. See https://github.com/psobot/keynote-parser/pull/48/files.