Skip to content

Commit d4a3888

Browse files
committed
add check to ensure ex:bitOffset is valid
1 parent 7415c62 commit d4a3888

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

packages/core/src/codecs/octetstream-codec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,18 @@ export default class OctetstreamCodec implements ContentCodec {
543543
throw new Error("Missing 'length' parameter necessary for write");
544544
}
545545

546+
const length = parseInt(parameters.length);
546547
const offset = schema["ex:bitOffset"] !== undefined ? parseInt(schema["ex:bitOffset"]) : 0;
547-
result = result ?? Buffer.alloc(parseInt(parameters.length));
548+
549+
if (isNaN(offset) || offset < 0) {
550+
throw new Error("ex:bitOffset must be a non-negative number");
551+
}
552+
553+
if (offset > length * 8) {
554+
throw new Error(`ex:bitOffset ${offset} exceeds length ${length}`);
555+
}
556+
557+
result = result ?? Buffer.alloc(length);
548558
for (const propertyName in schema.properties) {
549559
if (Object.hasOwnProperty.call(value, propertyName) === false) {
550560
throw new Error(`Missing property '${propertyName}'`);

0 commit comments

Comments
 (0)