File tree Expand file tree Collapse file tree
packages/preview2-shim/lib/browser Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,6 +43,22 @@ const timeZero = {
4343 nanoseconds : 0 ,
4444} ;
4545
46+ /** Coerce the given object to a safe integer */
47+ function coerceToSafeIntegerNumber ( obj ) {
48+ let n ;
49+ if ( typeof obj === "number" ) {
50+ n = obj ;
51+ } else if ( typeof obj == "bigint" ) {
52+ n = Number ( obj ) ;
53+ } else {
54+ throw new TypeError ( `unexpected non-numeric type: ${ obj } ` ) ;
55+ }
56+ if ( n > Number . MAX_SAFE_INTEGER ) {
57+ throw new TypeError ( `excessively large number: ${ n } ` ) ;
58+ }
59+ return n ;
60+ }
61+
4662function getChildEntry ( parentEntry , subpath , openFlags ) {
4763 if ( subpath === "." && _rootPreopen && descriptorGetEntry ( _rootPreopen [ 0 ] ) === parentEntry ) {
4864 subpath = _getCwd ( ) ;
@@ -188,8 +204,8 @@ class Descriptor {
188204
189205 read ( length , offset ) {
190206 const source = getSource ( this . #entry) ;
191- const off = typeof offset === "bigint" ? Number ( offset ) : offset ;
192- const len = typeof length === "bigint" ? Number ( length ) : length ;
207+ const off = coerceToSafeIntegerNumber ( offset ) ;
208+ const len = coerceToSafeIntegerNumber ( length ) ;
193209 return [ source . slice ( off , off + len ) , off + len >= source . byteLength ] ;
194210 }
195211
You can’t perform that action at this time.
0 commit comments