File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 } '` ) ;
You can’t perform that action at this time.
0 commit comments