@omnibuf/core 0.0.8 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blind.d.ts +3 -3
- package/dist/blind.d.ts.map +1 -1
- package/dist/blind.js +191 -31
- package/dist/blind.js.map +1 -1
- package/dist/encoder.d.ts +5 -5
- package/dist/encoder.d.ts.map +1 -1
- package/dist/encoder.js +25 -4
- package/dist/encoder.js.map +1 -1
- package/dist/protobuf-es.d.ts +2 -0
- package/dist/protobuf-es.d.ts.map +1 -1
- package/dist/protobuf-es.js +40 -8
- package/dist/protobuf-es.js.map +1 -1
- package/dist/readers.d.ts +4 -3
- package/dist/readers.d.ts.map +1 -1
- package/dist/readers.js +405 -120
- package/dist/readers.js.map +1 -1
- package/dist/schema.d.ts +9 -4
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +202 -79
- package/dist/schema.js.map +1 -1
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +16 -14
- package/dist/validation.js.map +1 -1
- package/dist/wire.d.ts +16 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +303 -23
- package/dist/wire.js.map +1 -1
- package/package.json +1 -1
package/dist/wire.js
CHANGED
|
@@ -58,7 +58,7 @@ export function parseArrayHeader(body, start = 0, end = body.length) {
|
|
|
58
58
|
cn = 2;
|
|
59
59
|
}
|
|
60
60
|
else {
|
|
61
|
-
const [count64, cBytes] = decodeVarintBigInt(body, start + 1);
|
|
61
|
+
const [count64, cBytes] = decodeVarintBigInt(body, start + 1, end);
|
|
62
62
|
if (cBytes === 0 || count64 > BigInt(end - (start + 1 + cBytes))) {
|
|
63
63
|
return [0, 0, 0, false];
|
|
64
64
|
}
|
|
@@ -91,7 +91,7 @@ export function parseArrayHeader(body, start = 0, end = body.length) {
|
|
|
91
91
|
return [0, 0, 0, false];
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
-
else if (countNum > remaining) {
|
|
94
|
+
else if (countNum === 0 ? remaining !== 0 : countNum > remaining) {
|
|
95
95
|
return [0, 0, 0, false];
|
|
96
96
|
}
|
|
97
97
|
return [elemType, countNum, pos, true];
|
|
@@ -133,7 +133,7 @@ export function parseMapHeader(body, start = 0, end = body.length) {
|
|
|
133
133
|
cn = 2;
|
|
134
134
|
}
|
|
135
135
|
else {
|
|
136
|
-
const [count64, cBytes] = decodeVarintBigInt(body, start + 2);
|
|
136
|
+
const [count64, cBytes] = decodeVarintBigInt(body, start + 2, end);
|
|
137
137
|
if (cBytes === 0 || count64 > BigInt(Math.floor((end - (start + 2 + cBytes)) / 2))) {
|
|
138
138
|
return [0, 0, 0, 0, false];
|
|
139
139
|
}
|
|
@@ -141,7 +141,7 @@ export function parseMapHeader(body, start = 0, end = body.length) {
|
|
|
141
141
|
cn = cBytes;
|
|
142
142
|
}
|
|
143
143
|
const pos = start + 2 + cn;
|
|
144
|
-
if (pos > end || countNum > (end - pos) >>> 1) {
|
|
144
|
+
if (pos > end || (countNum === 0 ? end !== pos : countNum > (end - pos) >>> 1)) {
|
|
145
145
|
return [0, 0, 0, 0, false];
|
|
146
146
|
}
|
|
147
147
|
return [keyWT, valWT, countNum, pos, true];
|
|
@@ -153,6 +153,10 @@ const sharedTextDecoder = new TextDecoder('utf-8', { fatal: true, ignoreBOM: tru
|
|
|
153
153
|
* Returns `null` if any byte is non-ASCII (`>= 0x80`) or if `end - start > 64`.
|
|
154
154
|
*/
|
|
155
155
|
export function fastDecodeShortASCII(bytes, start, end) {
|
|
156
|
+
if (start < 0)
|
|
157
|
+
start = 0;
|
|
158
|
+
if (end > bytes.length)
|
|
159
|
+
end = bytes.length;
|
|
156
160
|
const len = end - start;
|
|
157
161
|
if (len <= 0)
|
|
158
162
|
return '';
|
|
@@ -364,18 +368,27 @@ export function decodeZigZagBigInt(u) {
|
|
|
364
368
|
return BigInt.asIntN(64, (b >> 1n) ^ -(b & 1n));
|
|
365
369
|
}
|
|
366
370
|
/**
|
|
367
|
-
* Maps a ZigZag-encoded unsigned integer back to a signed JS number
|
|
368
|
-
* or bigint (when outside Number.MAX_SAFE_INTEGER).
|
|
371
|
+
* Maps a ZigZag-encoded unsigned integer back to a signed JS number.
|
|
369
372
|
*/
|
|
370
373
|
export function decodeZigZag(u) {
|
|
371
374
|
if (typeof u === 'number' && u <= 0xffffffff) {
|
|
372
|
-
|
|
375
|
+
const res = (u >>> 1) ^ -(u & 1);
|
|
376
|
+
return res === 0 ? 0 : res;
|
|
373
377
|
}
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
378
|
+
const n = Number(decodeZigZagBigInt(u));
|
|
379
|
+
return n === 0 ? 0 : n;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Maps a ZigZag-encoded unsigned integer back to a signed 32-bit JS number,
|
|
383
|
+
* retaining the exact low 32 bits even when the wire value exceeds 2^53.
|
|
384
|
+
*/
|
|
385
|
+
export function decodeZigZag32(u) {
|
|
386
|
+
if (typeof u === 'number' && u <= 0xffffffff) {
|
|
387
|
+
const res = (u >>> 1) ^ -(u & 1);
|
|
388
|
+
return res === 0 ? 0 : res;
|
|
377
389
|
}
|
|
378
|
-
|
|
390
|
+
const n = Number(BigInt.asIntN(32, decodeZigZagBigInt(u)));
|
|
391
|
+
return n === 0 ? 0 : n;
|
|
379
392
|
}
|
|
380
393
|
/**
|
|
381
394
|
* Decodes a ZigZag value returning a JS number when within safe integer bounds,
|
|
@@ -767,7 +780,7 @@ function isValidArrayHeaderAt(body, start, end) {
|
|
|
767
780
|
case WireSfixed64:
|
|
768
781
|
return (remaining & 7) === 0 && countNum === remaining >>> 3;
|
|
769
782
|
default:
|
|
770
|
-
return countNum <= remaining;
|
|
783
|
+
return countNum === 0 ? remaining === 0 : countNum <= remaining;
|
|
771
784
|
}
|
|
772
785
|
}
|
|
773
786
|
function isValidMapHeaderAt(body, start, end) {
|
|
@@ -807,7 +820,7 @@ function isValidMapHeaderAt(body, start, end) {
|
|
|
807
820
|
cn = cBytes;
|
|
808
821
|
}
|
|
809
822
|
const pos = start + 2 + cn;
|
|
810
|
-
return pos <= end && countNum <= (end - pos) >>> 1;
|
|
823
|
+
return pos <= end && (countNum === 0 ? end === pos : countNum <= (end - pos) >>> 1);
|
|
811
824
|
}
|
|
812
825
|
export function skipValidatedValue(b, pos, wireType) {
|
|
813
826
|
const n = b.length;
|
|
@@ -911,6 +924,257 @@ export function skipValue(b, pos, wireType) {
|
|
|
911
924
|
}
|
|
912
925
|
return nextPos;
|
|
913
926
|
}
|
|
927
|
+
function validateUnknownEntryAt(body, p, wt, depth, limit) {
|
|
928
|
+
if (wt === WireBoolFalse) {
|
|
929
|
+
if (p >= body.length || (body[p] !== 0 && body[p] !== 1))
|
|
930
|
+
return -1;
|
|
931
|
+
return p + 1;
|
|
932
|
+
}
|
|
933
|
+
if (wt === WireSubMsg) {
|
|
934
|
+
if (p >= body.length)
|
|
935
|
+
return -1;
|
|
936
|
+
const [bLen, bn] = decodeVarintBigInt(body, p);
|
|
937
|
+
if (bn === 0 || bLen > BigInt(body.length - (p + bn)))
|
|
938
|
+
return -1;
|
|
939
|
+
const start = p + bn;
|
|
940
|
+
const end = start + Number(bLen);
|
|
941
|
+
if (!validateUnknownMessageBytes(body.subarray(start, end), depth + 1, limit))
|
|
942
|
+
return -1;
|
|
943
|
+
return end;
|
|
944
|
+
}
|
|
945
|
+
if (wt === WireArray || wt === WireMap) {
|
|
946
|
+
return validateUnknownValueAt(body, p, wt, depth, limit);
|
|
947
|
+
}
|
|
948
|
+
return skipValidatedValue(body, p, wt);
|
|
949
|
+
}
|
|
950
|
+
function validateUnknownValueAt(data, pos, wt, depth, limit) {
|
|
951
|
+
if (depth > limit)
|
|
952
|
+
return -1;
|
|
953
|
+
if (wt === WireSubMsg) {
|
|
954
|
+
if (pos >= data.length)
|
|
955
|
+
return -1;
|
|
956
|
+
const [bLen, bn] = decodeVarintBigInt(data, pos);
|
|
957
|
+
if (bn === 0 || bLen > BigInt(data.length - (pos + bn)))
|
|
958
|
+
return -1;
|
|
959
|
+
const start = pos + bn;
|
|
960
|
+
const end = start + Number(bLen);
|
|
961
|
+
if (!validateUnknownMessageBytes(data.subarray(start, end), depth + 1, limit))
|
|
962
|
+
return -1;
|
|
963
|
+
return end;
|
|
964
|
+
}
|
|
965
|
+
if (wt === WireArray) {
|
|
966
|
+
if (depth + 1 > limit || pos >= data.length)
|
|
967
|
+
return -1;
|
|
968
|
+
const [bLen, bn] = decodeVarintBigInt(data, pos);
|
|
969
|
+
if (bn === 0 || bLen < 2n || bLen > BigInt(data.length - (pos + bn)))
|
|
970
|
+
return -1;
|
|
971
|
+
const end = pos + bn + Number(bLen);
|
|
972
|
+
const body = data.subarray(pos + bn, end);
|
|
973
|
+
const [elemType, count, startP, ok] = parseArrayHeader(body);
|
|
974
|
+
if (!ok)
|
|
975
|
+
return -1;
|
|
976
|
+
let p = startP;
|
|
977
|
+
if (elemType === WireBoolFalse) {
|
|
978
|
+
if (body.length - p !== count)
|
|
979
|
+
return -1;
|
|
980
|
+
for (let i = 0; i < count; i++) {
|
|
981
|
+
const b = body[p + i];
|
|
982
|
+
if (b !== 0 && b !== 1)
|
|
983
|
+
return -1;
|
|
984
|
+
}
|
|
985
|
+
return end;
|
|
986
|
+
}
|
|
987
|
+
if (elemType === WireFixed32 || elemType === WireSfixed32 || elemType === WireFloat32) {
|
|
988
|
+
return body.length - p === count * 4 ? end : -1;
|
|
989
|
+
}
|
|
990
|
+
if (elemType === WireFixed64 || elemType === WireSfixed64 || elemType === WireFloat64) {
|
|
991
|
+
return body.length - p === count * 8 ? end : -1;
|
|
992
|
+
}
|
|
993
|
+
for (let i = 0; i < count; i++) {
|
|
994
|
+
p = validateUnknownEntryAt(body, p, elemType, depth + 1, limit);
|
|
995
|
+
if (p < 0)
|
|
996
|
+
return -1;
|
|
997
|
+
}
|
|
998
|
+
return p === body.length ? end : -1;
|
|
999
|
+
}
|
|
1000
|
+
if (wt === WireMap) {
|
|
1001
|
+
if (depth + 1 > limit || pos >= data.length)
|
|
1002
|
+
return -1;
|
|
1003
|
+
const [bLen, bn] = decodeVarintBigInt(data, pos);
|
|
1004
|
+
if (bn === 0 || bLen < 3n || bLen > BigInt(data.length - (pos + bn)))
|
|
1005
|
+
return -1;
|
|
1006
|
+
const end = pos + bn + Number(bLen);
|
|
1007
|
+
const body = data.subarray(pos + bn, end);
|
|
1008
|
+
const [keyWT, valWT, count, startP, ok] = parseMapHeader(body);
|
|
1009
|
+
if (!ok)
|
|
1010
|
+
return -1;
|
|
1011
|
+
let p = startP;
|
|
1012
|
+
for (let i = 0; i < count; i++) {
|
|
1013
|
+
p = validateUnknownEntryAt(body, p, keyWT, depth + 1, limit);
|
|
1014
|
+
if (p < 0)
|
|
1015
|
+
return -1;
|
|
1016
|
+
p = validateUnknownEntryAt(body, p, valWT, depth + 1, limit);
|
|
1017
|
+
if (p < 0)
|
|
1018
|
+
return -1;
|
|
1019
|
+
}
|
|
1020
|
+
return p === body.length ? end : -1;
|
|
1021
|
+
}
|
|
1022
|
+
return skipValidatedValue(data, pos, wt);
|
|
1023
|
+
}
|
|
1024
|
+
function validateUnknownMessageBytes(data, depth, limit = MaxNestingDepth) {
|
|
1025
|
+
if (depth > limit)
|
|
1026
|
+
return false;
|
|
1027
|
+
let pos = 0;
|
|
1028
|
+
while (pos < data.length) {
|
|
1029
|
+
const [tag, tn] = decodeVarintBigInt(data, pos);
|
|
1030
|
+
if (tn === 0 || tag >> 4n > 536870911n)
|
|
1031
|
+
return false;
|
|
1032
|
+
pos += tn;
|
|
1033
|
+
const fnum = Number(tag >> 4n);
|
|
1034
|
+
const wt = Number(tag & 0x0fn);
|
|
1035
|
+
if (fnum === 0) {
|
|
1036
|
+
const nextPos = validateField0At(data, pos, wt, depth, limit);
|
|
1037
|
+
if (nextPos < 0)
|
|
1038
|
+
return false;
|
|
1039
|
+
pos = nextPos;
|
|
1040
|
+
}
|
|
1041
|
+
else {
|
|
1042
|
+
const nextPos = validateUnknownValueAt(data, pos, wt, depth, limit);
|
|
1043
|
+
if (nextPos < 0)
|
|
1044
|
+
return false;
|
|
1045
|
+
pos = nextPos;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return true;
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Validates an `omnibuf.v1.SchemaMeta` payload at `depth`.
|
|
1052
|
+
*/
|
|
1053
|
+
export function validateSchemaMetaBytes(data, depth, limit = MaxNestingDepth) {
|
|
1054
|
+
if (depth > limit)
|
|
1055
|
+
return false;
|
|
1056
|
+
let pos = 0;
|
|
1057
|
+
const n = data.length;
|
|
1058
|
+
while (pos < n) {
|
|
1059
|
+
const [tag, tn] = decodeVarintBigInt(data, pos);
|
|
1060
|
+
if (tn === 0 || tag >> 4n > 536870911n)
|
|
1061
|
+
return false;
|
|
1062
|
+
pos += tn;
|
|
1063
|
+
const fnum = Number(tag >> 4n);
|
|
1064
|
+
const wt = Number(tag & 0x0fn);
|
|
1065
|
+
switch (fnum) {
|
|
1066
|
+
case 1: {
|
|
1067
|
+
if (wt !== WireString || pos >= n)
|
|
1068
|
+
return false;
|
|
1069
|
+
const [sLen, sn] = decodeVarintBigInt(data, pos);
|
|
1070
|
+
if (sn === 0 || sLen > BigInt(n - (pos + sn)))
|
|
1071
|
+
return false;
|
|
1072
|
+
pos += sn;
|
|
1073
|
+
const end = pos + Number(sLen);
|
|
1074
|
+
try {
|
|
1075
|
+
decodeUTF8(data, pos, end);
|
|
1076
|
+
}
|
|
1077
|
+
catch {
|
|
1078
|
+
return false;
|
|
1079
|
+
}
|
|
1080
|
+
pos = end;
|
|
1081
|
+
break;
|
|
1082
|
+
}
|
|
1083
|
+
case 2: {
|
|
1084
|
+
if (wt !== WireMap || depth + 1 > limit || pos >= n)
|
|
1085
|
+
return false;
|
|
1086
|
+
const [bLen, bn] = decodeVarintBigInt(data, pos);
|
|
1087
|
+
if (bn === 0 || bLen < 3n || bLen > BigInt(n - (pos + bn)))
|
|
1088
|
+
return false;
|
|
1089
|
+
const bodyEnd = pos + bn + Number(bLen);
|
|
1090
|
+
const body = data.subarray(pos + bn, bodyEnd);
|
|
1091
|
+
pos = bodyEnd;
|
|
1092
|
+
const [keyWT, valWT, count, startP, ok] = parseMapHeader(body);
|
|
1093
|
+
if (!ok || keyWT !== WireUint || valWT !== WireString)
|
|
1094
|
+
return false;
|
|
1095
|
+
let p = startP;
|
|
1096
|
+
for (let i = 0; i < count; i++) {
|
|
1097
|
+
const [k64, kn] = decodeVarintBigInt(body, p);
|
|
1098
|
+
if (kn === 0 || k64 === 0n || k64 > 536870911n)
|
|
1099
|
+
return false;
|
|
1100
|
+
p += kn;
|
|
1101
|
+
const [sLen, sn] = decodeVarintBigInt(body, p);
|
|
1102
|
+
if (sn === 0 || sLen > BigInt(body.length - (p + sn)))
|
|
1103
|
+
return false;
|
|
1104
|
+
p += sn;
|
|
1105
|
+
const sEnd = p + Number(sLen);
|
|
1106
|
+
try {
|
|
1107
|
+
decodeUTF8(body, p, sEnd);
|
|
1108
|
+
}
|
|
1109
|
+
catch {
|
|
1110
|
+
return false;
|
|
1111
|
+
}
|
|
1112
|
+
p = sEnd;
|
|
1113
|
+
}
|
|
1114
|
+
if (p !== body.length)
|
|
1115
|
+
return false;
|
|
1116
|
+
break;
|
|
1117
|
+
}
|
|
1118
|
+
case 3: {
|
|
1119
|
+
if (wt !== WireMap || depth + 1 > limit || pos >= n)
|
|
1120
|
+
return false;
|
|
1121
|
+
const [bLen, bn] = decodeVarintBigInt(data, pos);
|
|
1122
|
+
if (bn === 0 || bLen < 3n || bLen > BigInt(n - (pos + bn)))
|
|
1123
|
+
return false;
|
|
1124
|
+
const bodyEnd = pos + bn + Number(bLen);
|
|
1125
|
+
const body = data.subarray(pos + bn, bodyEnd);
|
|
1126
|
+
pos = bodyEnd;
|
|
1127
|
+
const [keyWT, valWT, count, startP, ok] = parseMapHeader(body);
|
|
1128
|
+
if (!ok || keyWT !== WireUint || valWT !== WireSubMsg)
|
|
1129
|
+
return false;
|
|
1130
|
+
let p = startP;
|
|
1131
|
+
for (let i = 0; i < count; i++) {
|
|
1132
|
+
const [k64, kn] = decodeVarintBigInt(body, p);
|
|
1133
|
+
if (kn === 0 || k64 === 0n || k64 > 536870911n)
|
|
1134
|
+
return false;
|
|
1135
|
+
p += kn;
|
|
1136
|
+
const [cLen, cn] = decodeVarintBigInt(body, p);
|
|
1137
|
+
if (cn === 0 || cLen > BigInt(body.length - (p + cn)))
|
|
1138
|
+
return false;
|
|
1139
|
+
p += cn;
|
|
1140
|
+
const cEnd = p + Number(cLen);
|
|
1141
|
+
if (!validateSchemaMetaBytes(body.subarray(p, cEnd), depth + 2, limit))
|
|
1142
|
+
return false;
|
|
1143
|
+
p = cEnd;
|
|
1144
|
+
}
|
|
1145
|
+
if (p !== body.length)
|
|
1146
|
+
return false;
|
|
1147
|
+
break;
|
|
1148
|
+
}
|
|
1149
|
+
default: {
|
|
1150
|
+
if (fnum === 0)
|
|
1151
|
+
return false;
|
|
1152
|
+
const nextPos = validateUnknownValueAt(data, pos, wt, depth, limit);
|
|
1153
|
+
if (nextPos < 0)
|
|
1154
|
+
return false;
|
|
1155
|
+
pos = nextPos;
|
|
1156
|
+
break;
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
return true;
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Validates a `Field #0` (`omnibuf.v1.SchemaMeta`) entry starting at value offset `pos`.
|
|
1164
|
+
* Returns the end offset after `Field #0`, or `-1` if invalid.
|
|
1165
|
+
*/
|
|
1166
|
+
export function validateField0At(packet, pos, wt, depth = 0, limit = MaxNestingDepth) {
|
|
1167
|
+
if (wt !== WireSubMsg || pos < 0 || pos >= packet.length)
|
|
1168
|
+
return -1;
|
|
1169
|
+
const [bLen, bn] = decodeVarintBigInt(packet, pos);
|
|
1170
|
+
if (bn === 0 || bLen > BigInt(packet.length - (pos + bn)))
|
|
1171
|
+
return -1;
|
|
1172
|
+
const start = pos + bn;
|
|
1173
|
+
const end = start + Number(bLen);
|
|
1174
|
+
if (!validateSchemaMetaBytes(packet.subarray(start, end), depth + 1, limit))
|
|
1175
|
+
return -1;
|
|
1176
|
+
return end;
|
|
1177
|
+
}
|
|
914
1178
|
const NOT_FOUND = {
|
|
915
1179
|
valSlice: new Uint8Array(0),
|
|
916
1180
|
valPos: 0,
|
|
@@ -922,7 +1186,7 @@ const NOT_FOUND = {
|
|
|
922
1186
|
* using TZCNT length prefixes (without parsing inside preceding strings, sub-messages, or arrays).
|
|
923
1187
|
* Scans all field headers in the message and returns the last matching occurrence ("last write wins").
|
|
924
1188
|
*/
|
|
925
|
-
export function locateField(packet, targetField) {
|
|
1189
|
+
export function locateField(packet, targetField, expMask = 0xffff) {
|
|
926
1190
|
let pos = 0;
|
|
927
1191
|
const n = packet.length;
|
|
928
1192
|
let lastPos = -1;
|
|
@@ -953,10 +1217,19 @@ export function locateField(packet, targetField) {
|
|
|
953
1217
|
wt = Number(tag & 0x0fn);
|
|
954
1218
|
pos += tn;
|
|
955
1219
|
}
|
|
956
|
-
if (fnum === 0
|
|
957
|
-
|
|
1220
|
+
if (fnum === 0) {
|
|
1221
|
+
const f0End = validateField0At(packet, pos, wt, 0);
|
|
1222
|
+
if (f0End < 0) {
|
|
1223
|
+
return NOT_FOUND;
|
|
1224
|
+
}
|
|
1225
|
+
if (targetField === 0 && ((expMask >>> wt) & 1) !== 0) {
|
|
1226
|
+
lastPos = pos;
|
|
1227
|
+
lastWT = wt;
|
|
1228
|
+
}
|
|
1229
|
+
pos = f0End;
|
|
1230
|
+
continue;
|
|
958
1231
|
}
|
|
959
|
-
if (fnum === targetField) {
|
|
1232
|
+
if (fnum === targetField && ((expMask >>> wt) & 1) !== 0) {
|
|
960
1233
|
lastPos = pos;
|
|
961
1234
|
lastWT = wt;
|
|
962
1235
|
}
|
|
@@ -1009,11 +1282,19 @@ export function nextContainerField(packet, pos, targetField, expWT, minLen) {
|
|
|
1009
1282
|
wt = Number(tag & 0x0fn);
|
|
1010
1283
|
pos += tn;
|
|
1011
1284
|
}
|
|
1285
|
+
if (fnum === 0 && targetField !== 0) {
|
|
1286
|
+
const f0End = validateField0At(packet, pos, wt, 0);
|
|
1287
|
+
if (f0End < 0) {
|
|
1288
|
+
return { body: new Uint8Array(0), nextPos: 0, matched: false, valid: false };
|
|
1289
|
+
}
|
|
1290
|
+
pos = f0End;
|
|
1291
|
+
continue;
|
|
1292
|
+
}
|
|
1012
1293
|
if (fnum === 0 && wt !== WireSubMsg) {
|
|
1013
1294
|
return { body: new Uint8Array(0), nextPos: 0, matched: false, valid: false };
|
|
1014
1295
|
}
|
|
1015
|
-
if (fnum === targetField) {
|
|
1016
|
-
if (
|
|
1296
|
+
if (fnum === targetField && wt === expWT) {
|
|
1297
|
+
if (pos >= n) {
|
|
1017
1298
|
return { body: new Uint8Array(0), nextPos: 0, matched: false, valid: false };
|
|
1018
1299
|
}
|
|
1019
1300
|
let lenNum = 0;
|
|
@@ -1050,12 +1331,11 @@ export function nextContainerField(packet, pos, targetField, expWT, minLen) {
|
|
|
1050
1331
|
valid: true,
|
|
1051
1332
|
};
|
|
1052
1333
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
}
|
|
1056
|
-
catch {
|
|
1334
|
+
const nextPos = skipValidatedValue(packet, pos, wt);
|
|
1335
|
+
if (nextPos < 0) {
|
|
1057
1336
|
return { body: new Uint8Array(0), nextPos: 0, matched: false, valid: false };
|
|
1058
1337
|
}
|
|
1338
|
+
pos = nextPos;
|
|
1059
1339
|
}
|
|
1060
1340
|
return { body: new Uint8Array(0), nextPos: n, matched: false, valid: true };
|
|
1061
1341
|
}
|