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

Substring 'not' cannot be used in expressions #556

Closed
closer76 opened this issue Apr 3, 2019 · 4 comments
Closed

Substring 'not' cannot be used in expressions #556

closer76 opened this issue Apr 3, 2019 · 4 comments
Milestone

Comments

@closer76
Copy link

closer76 commented Apr 3, 2019

(The following tests are done in web IDE)

Suppose we want to parse a UTF-16 string with character length info described as u2. The .ksy is defined like this.

meta:
  id: test_bug
  file-extension: .bin
  endian: le
seq:
  - id: note_len
    type: u2
  - id: note
    type: str
    size: note_len * 2
    encoding: UTF-16LE

Unfortunately, it raises exception as below:

Parse error: undefined
Call stack: Error
    at $c_Lio_kaitai_struct_precompile_ErrorInInput.fillInStackTrace__jl_Throwable (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:20102:14)
    at $c_Lio_kaitai_struct_precompile_ErrorInInput.init___T__jl_Throwable (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:20124:8)
    at $c_Lio_kaitai_struct_precompile_ErrorInInput.init___jl_Throwable__sci_List__s_Option (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:55387:52)
    at $c_Lio_kaitai_struct_precompile_TypeValidator.run__V (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:8842:70)
    at $c_Lio_kaitai_struct_Main$.precompile__Lio_kaitai_struct_format_ClassSpecs__Lio_kaitai_struct_format_ClassSpec__Lio_kaitai_struct_RuntimeConfig__V (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:3552:156)
    at https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:3506:38
    at $c_sjsr_AnonFunction1.apply__O__O (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:28035:23)
    at $c_s_util_Success.map__F1__s_util_Try (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:46244:47)
    at https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:13405:18
    at $c_sjsr_AnonFunction1.apply__O__O (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:28035:23)
    at $f_s_concurrent_impl_Promise__liftedTree1$1__ps_concurrent_impl_Promise__F1__s_util_Try__s_util_Try (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:26941:31)
    at https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:26933:22
    at $c_sjsr_AnonFunction1.apply__O__O (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:28035:23)
    at $c_s_concurrent_impl_CallbackRunnable.run__V (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:26813:23)
    at $c_sjs_concurrent_QueueExecutionContext$PromisesExecutionContext.scala$scalajs$concurrent$QueueExecutionContext$PromisesExecutionContext$$$anonfun$execute$2__sr_BoxedUnit__jl_Runnable__sjs_js_$bar (https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:33041:16)
    at https://ide.kaitai.io/lib/_npm/kaitai-struct-compiler/kaitai-struct-compiler.js:33058:24 io.kaitai.struct.precompile.ErrorInInput: test_bug: /seq/1/size: unable to access 'e_len' in test_bug context

This is because not as the substring of note_len is treated as a keyword in expressions, even if it should be part of an identifier.

It should not be treated as a separated keyword to avoid confusing.

A little test file is attached as below (zipped since .bin is not allowed to be uploaded).
TestBin.zip

@GreyCat
Copy link
Member

GreyCat commented Apr 3, 2019

A very good catch, thanks!

@GreyCat
Copy link
Member

GreyCat commented Apr 3, 2019

Added 2 tests that reproduce this behavior: kaitai-io/kaitai_struct_compiler@6996086

Currently, note_len parsing fails exactly as you've described.

@GreyCat
Copy link
Member

GreyCat commented Apr 3, 2019

Fix delivered: kaitai-io/kaitai_struct_compiler@0221a5a

Updated compiler will be available as unstable build in CI in 10-15 minutes.

@GreyCat GreyCat added this to the v0.9 milestone Apr 3, 2019
@closer76
Copy link
Author

closer76 commented Apr 9, 2019

Tested with kaitai-io/kaitai_struct_compiler@809c0bc and seemed good.

@closer76 closer76 closed this as completed Apr 9, 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

2 participants