native-run: RangeError [ERR_OUT_OF_RANGE]

Version: native-run: 0.2.7 node: 10.16.0

Description: Native-run fails when running both through ionic run ios and when running native-run directly. I’ve tried running ionic run ios both with and without the --l flag with same result. Tried running native-run ios --app "platforms/ios/build/device/App Admin.ipa" --device --connect --forward 8100:8100 with same result.

Command Output:

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 37. Received 38
    at boundsError (internal/buffer.js:49:9)
    at writeU_Int8 (internal/buffer.js:558:5)
    at Buffer.writeUInt8 (internal/buffer.js:565:10)
    at toCString (/Users/antongildebrand/.nvm/versions/node/v10.16.0/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:150:9)
    at AFCClient.makeDirectory (/Users/antongildebrand/.nvm/versions/node/v10.16.0/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:84:19)
    at AFCClient.uploadDirectory (/Users/antongildebrand/.nvm/versions/node/v10.16.0/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:89:20)
    at uploadApp (/Users/antongildebrand/.nvm/versions/node/v10.16.0/lib/node_modules/native-run/dist/ios/utils/device.js:85:21)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Environment Info:

Ionic:

   Ionic CLI                     : 5.2.1 (/Users/antongildebrand/.nvm/versions/node/v10.16.0/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.5.0
   @angular-devkit/build-angular : 0.13.9
   @angular-devkit/schematics    : 7.3.9
   @angular/cli                  : 7.3.9
   @ionic/angular-toolkit        : 1.5.1

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : ios 5.0.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.1, (and 8 other plugins)

Utility:

   cordova-res : not installed
   native-run  : 0.2.7

System:

   Android SDK Tools : 26.1.1 (/Users/antongildebrand/Library/android-sdk-macosx)
   ios-deploy        : 1.9.4
   ios-sim           : 8.0.1
   NodeJS            : v10.16.0 (/Users/antongildebrand/.nvm/versions/node/v10.16.0/bin/node)
   npm               : 6.9.0
   OS                : macOS Mojave
   Xcode             : Xcode 10.2.1 Build version 10E1001

macOS version: 10.14.5

Xcode version: 10.2.1

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 24 (3 by maintainers)

Most upvoted comments

Any news on the issue?

We found out the error was caused by non-ascii characters in path names.

The s is some file path and please see the below result:

> Buffer.byteLength("—")
3
> "—".length
1

If you want to know which path is, run this file in the directory under investigation:

const fs = require("fs");
const path = require("path");

function* walkSync(dir) {
  const files = fs.readdirSync(dir, { withFileTypes: true });
  for (const file of files) {
    if (file.isDirectory()) {
      yield* walkSync(path.join(dir, file.name));
    } else {
      yield path.join(dir, file.name);
    }
  }
}

for (const filePath of walkSync(__dirname)) {
  if (Buffer.byteLength(filePath) != filePath.length) {
    console.log(filePath);
  }
}

Ref: https://stackoverflow.com/a/66083078

As stated by @cxcxcxcx, a temporary fix is to open /node_modules/native-run/dist/ios/lib/client/afc.js and around line 160 change const buf = Buffer.alloc(s.length + 1); with const buf = Buffer.alloc(Buffer.byteLength(s) + 1);

Of course this is not a real solution, it will happen again as you run npm i. But it works until native-run gets updated.

Sigh, turns out that it’s in https://www.npmjs.com/package/node-ioslib , which is not open sourced.

In the generated afs.js, it’s clear that var buf = Buffer.alloc(s.length + 1); should be replaced by var buf = Buffer.alloc(Buffer.byteLength(s) + 1);

Also, all the strings responded should be decoded with UTF-8, rather than String.fromCharCode(token)

I’m getting the same error. My output:

client:afc closeFile fd: 185,0,0,0,0,0,0,0 +0ms
  client:afc closeFile fd: 186,0,0,0,0,0,0,0 +0ms
  protocol:afc parse header: {"magic":"CFA6LPAA","totalLength":48,"headerLength":48,"requestId":1035,"operation":14} +2ms
  protocol:afc FILE_OPEN_RES response: [object Object] +0ms
  protocol:afc parse header: {"magic":"CFA6LPAA","totalLength":48,"headerLength":48,"requestId":1036,"operation":14} +0ms
  protocol:afc FILE_OPEN_RES response: [object Object] +0ms
  protocol:afc parse header: {"magic":"CFA6LPAA","totalLength":48,"headerLength":48,"requestId":1037,"operation":14} +0ms
  protocol:afc FILE_OPEN_RES response: [object Object] +0ms
  protocol:afc parse header: {"magic":"CFA6LPAA","totalLength":48,"headerLength":48,"requestId":1038,"operation":14} +0ms
  protocol:afc FILE_OPEN_RES response: [object Object] +0ms
  protocol:afc parse header: {"magic":"CFA6LPAA","totalLength":48,"headerLength":48,"requestId":1039,"operation":14} +0ms
  protocol:afc FILE_OPEN_RES response: [object Object] +0ms
  client:afc writeFile: 187,0,0,0,0,0,0,0 +1ms
  client:afc writeFile: 188,0,0,0,0,0,0,0 +0ms
  client:afc writeFile: 189,0,0,0,0,0,0,0 +0ms
  client:afc writeFile: 190,0,0,0,0,0,0,0 +0ms
  client:afc writeFile: 191,0,0,0,0,0,0,0 +0ms
  client:afc closeFile fd: 187,0,0,0,0,0,0,0 +0ms
  client:afc closeFile fd: 188,0,0,0,0,0,0,0 +0ms
  client:afc closeFile fd: 189,0,0,0,0,0,0,0 +0ms
  client:afc closeFile fd: 190,0,0,0,0,0,0,0 +1ms
  client:afc closeFile fd: 191,0,0,0,0,0,0,0 +0ms
  native-run Caught fatal error: RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 59. Received 60
  native-run     at boundsError (internal/buffer.js:49:9)
  native-run     at writeU_Int8 (internal/buffer.js:558:5)
  native-run     at Buffer.writeUInt8 (internal/buffer.js:565:10)
  native-run     at toCString (/usr/local/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:150:9)
  native-run     at AFCClient.openFile (/usr/local/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:50:9)
  native-run     at AFCClient.uploadFile (/usr/local/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:69:24) +0ms
RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 59. Received 60
    at boundsError (internal/buffer.js:49:9)
    at writeU_Int8 (internal/buffer.js:558:5)
    at Buffer.writeUInt8 (internal/buffer.js:565:10)
    at toCString (/usr/local/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:150:9)
    at AFCClient.openFile (/usr/local/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:50:9)
    at AFCClient.uploadFile (/usr/local/lib/node_modules/native-run/node_modules/node-ioslib/dist/client/afc.js:69:24)
  client:afc openFile: PublicStaging/Moments.app/www/assets/pruebas.mp3 +83ms