Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/utils/KBinJSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,16 @@ function nodeToBinary(
binaryType = 'u8';
}

// Normalize missing or malformed content so kencode doesn't crash.
if (value === null || value === undefined) {
// If node is flagged as array (via __count), default to an empty array.
// Otherwise default to a single zero value for numeric types.
value = isArray ? [] : [0];
} else if (!Array.isArray(value)) {
// Ensure numeric/binary values are arrays for the writer APIs.
value = [value as number | bigint];
}

if (isArray) {
dataBuf.writeArray(binaryType as BinaryLengthType, value as (number | bigint)[]);
} else {
Expand Down
Loading