fix(client): keep array index 0 in ReadProperty and WriteProperty requests - #191
Open
chowchin wants to merge 1 commit into
Open
fix(client): keep array index 0 in ReadProperty and WriteProperty requests#191chowchin wants to merge 1 commit into
chowchin wants to merge 1 commit into
Conversation
…uests Index 0 of a BACnet array property holds the number of elements, which is how a client discovers the size of a property such as object-list before reading its entries individually. Both the client option handling and the ReadProperty encoder passed the index through 'arrayIndex || ASN1_ARRAY_ALL', which turns the valid index 0 into ASN1_ARRAY_ALL and therefore requests the entire array instead. On a device with a large object-list that whole-array response does not fit into a single APDU, so the request is aborted or times out and the client never learns the object count.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Index 0 of a BACnet array property holds the number of elements. Reading it is how a client finds out how large a property such as
object-listis, before reading the entries one by one — the standard fallback when the whole array does not fit in a single APDU.Two places pass the index through
arrayIndex || ASN1_ARRAY_ALL, so the valid index0becomesASN1_ARRAY_ALLand the request asks for the entire array instead:lib/client.js—readPropertyandwritePropertyoption handlinglib/services/read-property.js— the request encoderRound trip on master:
The outer guard
if (arrayIndex !== baEnum.ASN1_ARRAY_ALL)already establishes that an index was requested, so the||fallback inside it can only misfire — it is unreachable for every value except0, which it corrupts.Practical effect: against a device with a few thousand objects, reading
object-list[0]returnsAbort(segmentation-not-supported)(or overflows the APDU buffer) rather than the object count, so discovery cannot proceed.Change
Pass the index through unchanged in the encoder, and in
client.jsfall back toASN1_ARRAY_ALLonly whenarrayIndexwas not supplied. The explicit!== undefinedcheck is used rather than??to stay within the declarednode >= 12engine range.lib/services/write-property.jsalready encoded the index correctly; only the client-side option handling needed the same treatment.Tests
Added an index-0 round trip to
test/unit/service-read-property.spec.js. It fails on master:and passes with this change. Full unit suite: 33 suites, 118 tests, all passing.