-
Notifications
You must be signed in to change notification settings - Fork 199
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
The if
expression in value instances is not type-checked
#1129
Comments
To be honest, I don't see much value in these elaborate tables. In summary, type checking:
So the second " Other remarks in the first table are just repeating what has been reported before in other issues:
See #685
See #404 I don't really see anything new in what you wrote, except for the simple fact that " I thought you would already know about the 2 existing issues because you've encountered them in the past: |
Or let's clearly indicate that this issue only reports missing type checks on |
if
expression in value instances is not type-checked
Yes, the intention was just about this missing check. Those tables just an extract from my work-in-progress of documenting in which contexts each special variable:
That is why it contains more information than needed just for this issue. The idea that with each property with expression an unique context should be assigned which determines which special variables can be used and how they should be translated. To achive that I firstly want to create test cases, check how things work currently and establish a correct behavior, because it seems that this work was never done before. Some issues created here and there but without overall picture. |
If you want to report one bug, open a simple issue reporting that one bug. If you want to create a far-reaching issue that attempts to solve world hunger, please do so in another issue.
Please don't tell me that you knew about the existing issues but didn't even bother to look them up and refer to them. |
Huh?
following by the reproduction case and description of each variant.
No, I don't. Thanks that you found related issues. The most obvious "type check" request found nothing similar to this issue. |
Actually, meta:
id: issue1129
instances:
me:
value: 1
if: _ ...the following JS code is generated: Object.defineProperty(TestType.prototype, 'me', {
get: function() {
if (this._m_me !== undefined)
return this._m_me;
if (_) {
this._debug._m_me = { };
this._m_me = 1;
}
return this._m_me;
}
}); As it can be obviously seen, the and @GreyCat, why you added |
No, it shouldn't. This sounds like you don't have much experience writing or perhaps also reading .ksy files (I recommend doing it more, I've always enjoyed it). Ideally, if a .ksy specification is written properly and you're parsing a binary file that follows the format that the .ksy spec is for, you should be able to invoke all value instances and not get any errors or values that are meaningless because they're not applicable in the particular situation (so not only would they be calculated unnecessarily, but mainly their values could be misleading). Such errors or meaningless values would just confuse the user that inspects the object tree in visualizers, and especially nonsensical values would encourage misinterpretations when a user processes the Kaitai Struct object in their application. What do I mean by "errors"? Using seq:
- id: has_foo
type: b1
- id: foo
type: b7
if: has_foo
instances:
foo_as_signed:
value: (foo ^ 0x40) - 0x40
if: has_foo
doc-ref: https://graphics.stanford.edu/~seander/bithacks.html#VariableSignExtend Thanks to the But it's not only about NPEs. Sometimes you want to clearly mark the instance as "not applicable" even if a value could be calculated without errors. As one example of many, take a look at |
Currently I only check
<type>.instances.<instance>.if
, but I have feeling that the same problem exists for other fields where expression is allowed.Below the comparison between parse instance and value instance. There are many other problems with variables, but in this issue lets focus on missing checks of expression type:
Legend for the OK? column:
<type>.instances.<instance>.if
(parse instance)Parsed by
ParseUtils.getOptValueExpression
.Test KSY:
param
1seq
2seq
depends fromme
, then should be denied (currently it is allowed and we get error in runtime)instance
3seq
me
4unknown
5unable to access 'unknown' in <type name> context
. In is better to enclose<type name>
in quotes_
java.util.NoSuchElementException: None.get
_buf
invalid ID: '\_buf', expected /^[a-z][a-z0-9_]*$/
_index
i
in JS). Must be denied, because condition is checked before the loop, so even withrepeat
using this variable has no sense_io
_is_le
invalid ID: '\_is_le', expected /^[a-z][a-z0-9_]*$/
. If<type>
supports variable byte order, should be allowed_on
java.util.NoSuchElementException: None.get
_parent
_root
_sizeof
<type>
's size<type>.instances.<instance>.if
(value instance)Parsed by
ParseUtils.getOptValueExpression
.Test KSY:
param
1seq
2seq
depends ofme
instance
3instance
depends ofme
me
4unknown
5this.unknown
in JS)_
_
in JS)_buf
this._buf
in JS)_index
i
in JS). Must be denied, because condition is checked before the loop, so even withrepeat
using this variable has no sense_io
_is_le
this._isLe
in JS). If<type>
supports variable byte order, should be translated to check of the right field (this._is_le
in JS)_on
on
in JS)_parent
_root
_sizeof
<type>
's sizeFootnotes
parameter of the enclosing type ↩ ↩2
attribute of the enclosing type in
seq
section ↩ ↩2instance of the enclosing type in
instances
section ↩ ↩2reference to self ↩ ↩2
non-existent attribute or instance in the enclosing type ↩ ↩2
The text was updated successfully, but these errors were encountered: