Skip to content
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

Unexpected FieldTypeEnum while parsing specific jpegs #523

Closed
rjt-gupta opened this issue Feb 14, 2019 · 6 comments
Closed

Unexpected FieldTypeEnum while parsing specific jpegs #523

rjt-gupta opened this issue Feb 14, 2019 · 6 comments
Milestone

Comments

@rjt-gupta
Copy link

Hi! While parsing this JPEG with mitmproxy.

Traceback I got:
File "mitmproxy/contentviews/__init__.py", line 130, in get_content_view ERROR File "mitmproxy/contentviews/auto.py", line 17, in __call__ ERROR File "mitmproxy/contentviews/image/view.py", line 36, in __call__ ERROR File "mitmproxy/contentviews/image/image_parser.py", line 78, in parse_jpeg ERROR File "mitmproxy/contrib/kaitaistruct/exif_be.py", line 572, in ifd0 ERROR File "mitmproxy/contrib/kaitaistruct/exif_be.py", line 31, in __init__ ERROR File "mitmproxy/contrib/kaitaistruct/exif_be.py", line 522, in __init__ ERROR File "enum.py", line 291, in __call__ ERROR File "enum.py", line 533, in __new__ ERROR File "enum.py", line 546, in _missing_ ERROR ValueError: 9 is not a valid FieldTypeEnum ERROR

I think the main issue lies here. An unexpected FieldTypeEnum 9 is generated and throws error when field_type gets updated.

Would be glad to make changes to fix this.

@GreyCat
Copy link
Member

GreyCat commented Feb 16, 2019

The core problem lies in a fact that Python enum implementation throws an exception on encountering of value not specified in enum. Majority of other languages just treat it as null, or undefined, or just keep a numeric value. To some extent, it's being mentioned in #300, but there is no Python-specifid bug. Let us consider this one to be like that.

There are 2 ways to solve that specific problem you're mentioning:

  • Implement workaround for Python (probably add it to Python KS runtime + adjusting ksc output)
  • Fix exif_be to actually include value for FieldTypeEnum 9.

@GreyCat GreyCat added this to the v0.9 milestone Feb 16, 2019
@rjt-gupta
Copy link
Author

Hi! Thanks for looking into this.
I think the second way would be the best solution but not sure what would be the value for FieldTypeEnum 9 that has to be added in exif_be.
What do you think?

@KOLANICH
Copy link

Implement workaround for Python (probably add it to Python KS runtime + adjusting ksc output)

IMHO just a function returning either an IntEnum or just an integer is needed. And this behavior should be disableable. For example when debugging specs (usually I create a python script trying to parse all the files in a dir) a missing enum value means that I need something to be added.

@GreyCat
Copy link
Member

GreyCat commented Feb 17, 2019

JFYI, a similar thing already exists in Ruby runtime: https://github.com/kaitai-io/kaitai_struct_ruby_runtime/blob/master/lib/kaitai/struct/struct.rb#L478-L483

We just need similar one for Python.

@GreyCat
Copy link
Member

GreyCat commented Mar 4, 2019

Python-related problem fixed in kaitai-io/kaitai_struct_compiler@5039401

New test is called "enum_invalid": http://kaitai.io/ci/ci.html

Eventually to be implemented for all languages.

@GreyCat
Copy link
Member

GreyCat commented Apr 18, 2019

Test passes for all languages. Please reopen if any problems still remain.

@GreyCat GreyCat closed this as completed Apr 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants