-
Notifications
You must be signed in to change notification settings - Fork 68
Add records depth check #621
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
Conversation
Want me to merge? Or feel free to do it yourself |
I'll wait for others to chime in before doing so. Thank you! |
So the idea is to enforce a depth level hardcoded to 2 when creating NDEF messages from a source. There is no depth restriction on reads, right? Coming from there, I was pondering whether is it worth to expose the max depth to developers (up to a hardcoded ceiling bigger than 2), as a depth of 2 seems a good Gaussian value, but there might be use cases for more. I guess if that is the case, we'd get issues and could extend the API later. I am fine with 2. If all this is intended, LGTM. |
I think it's reasonable to allow a much deeper recursion depth (e.g. 32) on writes. On reads we don't need to worry because the depth is effectively limited by the length of the data received from the device. |
index.html
Outdated
initiating the function call, these will in practice be | ||
finite, so we work around this by using `any` as the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are tricky ways that a developer can craft an object that changes as the algorithm processes it. What I would say here instead is that for practical purposes there is only so much room for storing an NDEF message and so we can apply a limit on the depth of nested messages which developers are unlikely to ever hit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied
index.html
Outdated
To <dfn>map empty record to NDEF</dfn> given a |record:NDEFRecordInit| | ||
|ndef| and |context:string|, run these steps: | ||
To <dfn>map empty record to NDEF</dfn> given |record:NDEFRecordInit|, | ||
|ndef|, |context:string|, and |recordsDepth:unsigned short|, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we skip passing the depth to algorithms like this which don't use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done this for recordsDepth
and context
.
<ol> | ||
<li> | ||
Set the |ndef|'s <a>PAYLOAD field</a> to the result of running | ||
the <a>create NDEF message</a> given |record|'s <a>data</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data
here is any
while the "create NDEF message" record expects NDEFMessageSource
. It feels like we need to acknowledge this but maybe not because those steps do try to match on the parameter type and have a default case which will throw a TypeError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's okay to leave it as it. As you said, an unmatched type
will throw an error in the "create NDEF message" algorithm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed limit to 32
.
<ol> | ||
<li> | ||
Set the |ndef|'s <a>PAYLOAD field</a> to the result of running | ||
the <a>create NDEF message</a> given |record|'s <a>data</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's okay to leave it as it. As you said, an unmatched type
will throw an error in the "create NDEF message" algorithm
index.html
Outdated
To <dfn>map empty record to NDEF</dfn> given a |record:NDEFRecordInit| | ||
|ndef| and |context:string|, run these steps: | ||
To <dfn>map empty record to NDEF</dfn> given |record:NDEFRecordInit|, | ||
|ndef|, |context:string|, and |recordsDepth:unsigned short|, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done this for recordsDepth
and context
.
index.html
Outdated
initiating the function call, these will in practice be | ||
finite, so we work around this by using `any` as the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied
index.html
Outdated
<li> | ||
If |recordsDepth| > `32`, [= exception/throw =] a {{TypeError}} | ||
and abort these steps. | ||
<p class="issue" data-number="620"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be using class="issue"
here? Merging this change will resolve the issue so this should probably be a regular note, with reference to the issue that caused the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Implement w3c/web-nfc#621, which adds a hard-coded maximum of 32 NDEFMessage objects that can be in the same chain. w3c/web-nfc#454 (and https://chromium-review.googlesource.com/c/chromium/src/+/1941083 on the implementation side) ended up creating a cycle between NDEFRecordInit.data and NDEFMessageInit, as the former can be an NDEFMessage, which could have one or more entries pointing to the same NDEFRecordInit. Recursion in Web IDL dictionaries are disallowed, so this change also fixes some invalid IDL that was present in the spec and our IDL file. This CL attempts to optimize or modify other parts of the code as little as possible, but the the change ended up being a bit big mainly due to two things: - Since NDEFRecordInit.data's type is now `any`, we need to do more type conversions ourselves in NDEFRecord that we used to get for free when using IDL unions. This means attempting to convert a V8 value into one or more C++ types and accounting for conversion failures. - In order to do the above, we need access to v8::Isolate, so several functions in NDEFRecord that used to take an ExecutionContext needed to be changed to take a ScriptState instead. The usage of ScriptState and the need to perform multiple type conversions also caused NDEFReadingEvent's constructor to start passing one to NDEFMessage, which at the end causes the NDEFRecords that may get created to contain a proper `lang` attribute rather than null. This is a user-visible change, but I could not find anything in the spec supporting the previous behavior. Bug: 1242274 Change-Id: Ia4de230ea45f63f903760865bf85594f79da9eb7
Implement w3c/web-nfc#621, which adds a hard-coded maximum of 32 NDEFMessage objects that can be in the same chain. w3c/web-nfc#454 (and https://chromium-review.googlesource.com/c/chromium/src/+/1941083 on the implementation side) ended up creating a cycle between NDEFRecordInit.data and NDEFMessageInit, as the former can be an NDEFMessage, which could have one or more entries pointing to the same NDEFRecordInit. Recursion in Web IDL dictionaries are disallowed, so this change also fixes some invalid IDL that was present in the spec and our IDL file. This CL attempts to optimize or modify other parts of the code as little as possible, but the the change ended up being a bit big mainly due to two things: - Since NDEFRecordInit.data's type is now `any`, we need to do more type conversions ourselves in NDEFRecord that we used to get for free when using IDL unions. This means attempting to convert a V8 value into one or more C++ types and accounting for conversion failures. - In order to do the above, we need access to v8::Isolate, so several functions in NDEFRecord that used to take an ExecutionContext needed to be changed to take a ScriptState instead. The usage of ScriptState and the need to perform multiple type conversions also caused NDEFReadingEvent's constructor to start passing one to NDEFMessage, which at the end causes the NDEFRecords that may get created to contain a proper `lang` attribute rather than null. This is a user-visible change, but I could not find anything in the spec supporting the previous behavior. Bug: 1242274 Change-Id: Ia4de230ea45f63f903760865bf85594f79da9eb7
Implement w3c/web-nfc#621, which adds a hard-coded maximum of 32 NDEFMessage objects that can be in the same chain. w3c/web-nfc#454 (and https://chromium-review.googlesource.com/c/chromium/src/+/1941083 on the implementation side) ended up creating a cycle between NDEFRecordInit.data and NDEFMessageInit, as the former can be an NDEFMessage, which could have one or more entries pointing to the same NDEFRecordInit. Recursion in Web IDL dictionaries are disallowed, so this change also fixes some invalid IDL that was present in the spec and our IDL file. This CL attempts to optimize or modify other parts of the code as little as possible, but the the change ended up being a bit big mainly due to two things: - Since NDEFRecordInit.data's type is now `any`, we need to do more type conversions ourselves in NDEFRecord that we used to get for free when using IDL unions. This means attempting to convert a V8 value into one or more C++ types and accounting for conversion failures. - In order to do the above, we need access to v8::Isolate, so several functions in NDEFRecord that used to take an ExecutionContext needed to be changed to take a ScriptState instead. The usage of ScriptState and the need to perform multiple type conversions also caused NDEFReadingEvent's constructor to start passing one to NDEFMessage, which at the end causes the NDEFRecords that may get created to contain a proper `lang` attribute rather than null. This is a user-visible change, but I could not find anything in the spec supporting the previous behavior. Bug: 1242274 Change-Id: Ia4de230ea45f63f903760865bf85594f79da9eb7
Implement w3c/web-nfc#621, which adds a hard-coded maximum of 32 NDEFMessage objects that can be in the same chain. w3c/web-nfc#454 (and https://chromium-review.googlesource.com/c/chromium/src/+/1941083 on the implementation side) ended up creating a cycle between NDEFRecordInit.data and NDEFMessageInit, as the former can be an NDEFMessage, which could have one or more entries pointing to the same NDEFRecordInit. Recursion in Web IDL dictionaries are disallowed, so this change also fixes some invalid IDL that was present in the spec and our IDL file. This CL attempts to optimize or modify other parts of the code as little as possible, but the the change ended up being a bit big mainly due to two things: - Since NDEFRecordInit.data's type is now `any`, we need to do more type conversions ourselves in NDEFRecord that we used to get for free when using IDL unions. This means attempting to convert a V8 value into one or more C++ types and accounting for conversion failures. - In order to do the above, we need access to v8::Isolate, so several functions in NDEFRecord that used to take an ExecutionContext needed to be changed to take a ScriptState instead. The usage of ScriptState and the need to perform multiple type conversions also caused NDEFReadingEvent's constructor to start passing one to NDEFMessage, which at the end causes the NDEFRecords that may get created to contain a proper `lang` attribute rather than null. This is a user-visible change, but I could not find anything in the spec supporting the previous behavior. Bug: 1242274 Change-Id: Ia4de230ea45f63f903760865bf85594f79da9eb7
Implement w3c/web-nfc#621, which adds a hard-coded maximum of 32 NDEFMessage objects that can be in the same chain. w3c/web-nfc#454 (and https://chromium-review.googlesource.com/c/chromium/src/+/1941083 on the implementation side) ended up creating a cycle between NDEFRecordInit.data and NDEFMessageInit, as the former can be an NDEFMessage, which could have one or more entries pointing to the same NDEFRecordInit. Recursion in Web IDL dictionaries are disallowed, so this change also fixes some invalid IDL that was present in the spec and our IDL file. This CL attempts to optimize or modify other parts of the code as little as possible, but the the change ended up being a bit big mainly due to two things: - Since NDEFRecordInit.data's type is now `any`, we need to do more type conversions ourselves in NDEFRecord that we used to get for free when using IDL unions. This means attempting to convert a V8 value into one or more C++ types and accounting for conversion failures. - In order to do the above, we need access to v8::Isolate, so several functions in NDEFRecord that used to take an ExecutionContext needed to be changed to take a ScriptState instead. The usage of ScriptState and the need to perform multiple type conversions also caused NDEFReadingEvent's constructor to start passing one to NDEFMessage, which at the end causes the NDEFRecords that may get created to contain a proper `lang` attribute rather than null. This is a user-visible change, but I could not find anything in the spec supporting the previous behavior. Bug: 1242274 Change-Id: Ia4de230ea45f63f903760865bf85594f79da9eb7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3169656 Reviewed-by: Yuki Shiino <[email protected]> Reviewed-by: François Beaufort <[email protected]> Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Raphael Kubo da Costa <[email protected]> Cr-Commit-Position: refs/heads/main@{#925263}
Implement w3c/web-nfc#621, which adds a hard-coded maximum of 32 NDEFMessage objects that can be in the same chain. w3c/web-nfc#454 (and https://chromium-review.googlesource.com/c/chromium/src/+/1941083 on the implementation side) ended up creating a cycle between NDEFRecordInit.data and NDEFMessageInit, as the former can be an NDEFMessage, which could have one or more entries pointing to the same NDEFRecordInit. Recursion in Web IDL dictionaries are disallowed, so this change also fixes some invalid IDL that was present in the spec and our IDL file. This CL attempts to optimize or modify other parts of the code as little as possible, but the the change ended up being a bit big mainly due to two things: - Since NDEFRecordInit.data's type is now `any`, we need to do more type conversions ourselves in NDEFRecord that we used to get for free when using IDL unions. This means attempting to convert a V8 value into one or more C++ types and accounting for conversion failures. - In order to do the above, we need access to v8::Isolate, so several functions in NDEFRecord that used to take an ExecutionContext needed to be changed to take a ScriptState instead. The usage of ScriptState and the need to perform multiple type conversions also caused NDEFReadingEvent's constructor to start passing one to NDEFMessage, which at the end causes the NDEFRecords that may get created to contain a proper `lang` attribute rather than null. This is a user-visible change, but I could not find anything in the spec supporting the previous behavior. Bug: 1242274 Change-Id: Ia4de230ea45f63f903760865bf85594f79da9eb7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3169656 Reviewed-by: Yuki Shiino <[email protected]> Reviewed-by: François Beaufort <[email protected]> Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Raphael Kubo da Costa <[email protected]> Cr-Commit-Position: refs/heads/main@{#925263}
Implement w3c/web-nfc#621, which adds a hard-coded maximum of 32 NDEFMessage objects that can be in the same chain. w3c/web-nfc#454 (and https://chromium-review.googlesource.com/c/chromium/src/+/1941083 on the implementation side) ended up creating a cycle between NDEFRecordInit.data and NDEFMessageInit, as the former can be an NDEFMessage, which could have one or more entries pointing to the same NDEFRecordInit. Recursion in Web IDL dictionaries are disallowed, so this change also fixes some invalid IDL that was present in the spec and our IDL file. This CL attempts to optimize or modify other parts of the code as little as possible, but the the change ended up being a bit big mainly due to two things: - Since NDEFRecordInit.data's type is now `any`, we need to do more type conversions ourselves in NDEFRecord that we used to get for free when using IDL unions. This means attempting to convert a V8 value into one or more C++ types and accounting for conversion failures. - In order to do the above, we need access to v8::Isolate, so several functions in NDEFRecord that used to take an ExecutionContext needed to be changed to take a ScriptState instead. The usage of ScriptState and the need to perform multiple type conversions also caused NDEFReadingEvent's constructor to start passing one to NDEFMessage, which at the end causes the NDEFRecords that may get created to contain a proper `lang` attribute rather than null. This is a user-visible change, but I could not find anything in the spec supporting the previous behavior. Bug: 1242274 Change-Id: Ia4de230ea45f63f903760865bf85594f79da9eb7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3169656 Reviewed-by: Yuki Shiino <[email protected]> Reviewed-by: François Beaufort <[email protected]> Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Raphael Kubo da Costa <[email protected]> Cr-Commit-Position: refs/heads/main@{#925263}
…at can be nested., a=testonly Automatic update from web-platform-tests nfc: Limit amount NDEFMessage objects that can be nested. Implement w3c/web-nfc#621, which adds a hard-coded maximum of 32 NDEFMessage objects that can be in the same chain. w3c/web-nfc#454 (and https://chromium-review.googlesource.com/c/chromium/src/+/1941083 on the implementation side) ended up creating a cycle between NDEFRecordInit.data and NDEFMessageInit, as the former can be an NDEFMessage, which could have one or more entries pointing to the same NDEFRecordInit. Recursion in Web IDL dictionaries are disallowed, so this change also fixes some invalid IDL that was present in the spec and our IDL file. This CL attempts to optimize or modify other parts of the code as little as possible, but the the change ended up being a bit big mainly due to two things: - Since NDEFRecordInit.data's type is now `any`, we need to do more type conversions ourselves in NDEFRecord that we used to get for free when using IDL unions. This means attempting to convert a V8 value into one or more C++ types and accounting for conversion failures. - In order to do the above, we need access to v8::Isolate, so several functions in NDEFRecord that used to take an ExecutionContext needed to be changed to take a ScriptState instead. The usage of ScriptState and the need to perform multiple type conversions also caused NDEFReadingEvent's constructor to start passing one to NDEFMessage, which at the end causes the NDEFRecords that may get created to contain a proper `lang` attribute rather than null. This is a user-visible change, but I could not find anything in the spec supporting the previous behavior. Bug: 1242274 Change-Id: Ia4de230ea45f63f903760865bf85594f79da9eb7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3169656 Reviewed-by: Yuki Shiino <[email protected]> Reviewed-by: François Beaufort <[email protected]> Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Raphael Kubo da Costa <[email protected]> Cr-Commit-Position: refs/heads/main@{#925263} -- wpt-commits: d02695a83d483670b3cef6f2c6e492f698212700 wpt-pr: 30896
…at can be nested., a=testonly Automatic update from web-platform-tests nfc: Limit amount NDEFMessage objects that can be nested. Implement w3c/web-nfc#621, which adds a hard-coded maximum of 32 NDEFMessage objects that can be in the same chain. w3c/web-nfc#454 (and https://chromium-review.googlesource.com/c/chromium/src/+/1941083 on the implementation side) ended up creating a cycle between NDEFRecordInit.data and NDEFMessageInit, as the former can be an NDEFMessage, which could have one or more entries pointing to the same NDEFRecordInit. Recursion in Web IDL dictionaries are disallowed, so this change also fixes some invalid IDL that was present in the spec and our IDL file. This CL attempts to optimize or modify other parts of the code as little as possible, but the the change ended up being a bit big mainly due to two things: - Since NDEFRecordInit.data's type is now `any`, we need to do more type conversions ourselves in NDEFRecord that we used to get for free when using IDL unions. This means attempting to convert a V8 value into one or more C++ types and accounting for conversion failures. - In order to do the above, we need access to v8::Isolate, so several functions in NDEFRecord that used to take an ExecutionContext needed to be changed to take a ScriptState instead. The usage of ScriptState and the need to perform multiple type conversions also caused NDEFReadingEvent's constructor to start passing one to NDEFMessage, which at the end causes the NDEFRecords that may get created to contain a proper `lang` attribute rather than null. This is a user-visible change, but I could not find anything in the spec supporting the previous behavior. Bug: 1242274 Change-Id: Ia4de230ea45f63f903760865bf85594f79da9eb7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3169656 Reviewed-by: Yuki Shiino <[email protected]> Reviewed-by: François Beaufort <[email protected]> Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Raphael Kubo da Costa <[email protected]> Cr-Commit-Position: refs/heads/main@{#925263} -- wpt-commits: d02695a83d483670b3cef6f2c6e492f698212700 wpt-pr: 30896
Implement w3c/web-nfc#621, which adds a hard-coded maximum of 32 NDEFMessage objects that can be in the same chain. w3c/web-nfc#454 (and https://chromium-review.googlesource.com/c/chromium/src/+/1941083 on the implementation side) ended up creating a cycle between NDEFRecordInit.data and NDEFMessageInit, as the former can be an NDEFMessage, which could have one or more entries pointing to the same NDEFRecordInit. Recursion in Web IDL dictionaries are disallowed, so this change also fixes some invalid IDL that was present in the spec and our IDL file. This CL attempts to optimize or modify other parts of the code as little as possible, but the the change ended up being a bit big mainly due to two things: - Since NDEFRecordInit.data's type is now `any`, we need to do more type conversions ourselves in NDEFRecord that we used to get for free when using IDL unions. This means attempting to convert a V8 value into one or more C++ types and accounting for conversion failures. - In order to do the above, we need access to v8::Isolate, so several functions in NDEFRecord that used to take an ExecutionContext needed to be changed to take a ScriptState instead. The usage of ScriptState and the need to perform multiple type conversions also caused NDEFReadingEvent's constructor to start passing one to NDEFMessage, which at the end causes the NDEFRecords that may get created to contain a proper `lang` attribute rather than null. This is a user-visible change, but I could not find anything in the spec supporting the previous behavior. Bug: 1242274 Change-Id: Ia4de230ea45f63f903760865bf85594f79da9eb7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3169656 Reviewed-by: Yuki Shiino <[email protected]> Reviewed-by: François Beaufort <[email protected]> Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Raphael Kubo da Costa <[email protected]> Cr-Commit-Position: refs/heads/main@{#925263}
…at can be nested., a=testonly Automatic update from web-platform-tests nfc: Limit amount NDEFMessage objects that can be nested. Implement w3c/web-nfc#621, which adds a hard-coded maximum of 32 NDEFMessage objects that can be in the same chain. w3c/web-nfc#454 (and https://chromium-review.googlesource.com/c/chromium/src/+/1941083 on the implementation side) ended up creating a cycle between NDEFRecordInit.data and NDEFMessageInit, as the former can be an NDEFMessage, which could have one or more entries pointing to the same NDEFRecordInit. Recursion in Web IDL dictionaries are disallowed, so this change also fixes some invalid IDL that was present in the spec and our IDL file. This CL attempts to optimize or modify other parts of the code as little as possible, but the the change ended up being a bit big mainly due to two things: - Since NDEFRecordInit.data's type is now `any`, we need to do more type conversions ourselves in NDEFRecord that we used to get for free when using IDL unions. This means attempting to convert a V8 value into one or more C++ types and accounting for conversion failures. - In order to do the above, we need access to v8::Isolate, so several functions in NDEFRecord that used to take an ExecutionContext needed to be changed to take a ScriptState instead. The usage of ScriptState and the need to perform multiple type conversions also caused NDEFReadingEvent's constructor to start passing one to NDEFMessage, which at the end causes the NDEFRecords that may get created to contain a proper `lang` attribute rather than null. This is a user-visible change, but I could not find anything in the spec supporting the previous behavior. Bug: 1242274 Change-Id: Ia4de230ea45f63f903760865bf85594f79da9eb7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3169656 Reviewed-by: Yuki Shiino <[email protected]> Reviewed-by: François Beaufort <[email protected]> Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Raphael Kubo da Costa <[email protected]> Cr-Commit-Position: refs/heads/main@{#925263} -- wpt-commits: d02695a83d483670b3cef6f2c6e492f698212700 wpt-pr: 30896
This PR aims to solve infinite Web IDL loop introduced by #454. It does so by using
any
forNDEFRecordInit.data
and adding a depth-check step.FIX #620
Preview | Diff