RangeError: index out of range

本文介绍了一个关于Node.js中使用Buffer对象时遇到的读取越界错误。通过示例展示了如何创建一个Buffer对象并尝试读取超出其长度范围的数据导致的错误。文章最后给出了正确的索引值范围来避免此类问题。
部署运行你感兴趣的模型镜像

1、错误描述

> buffer=new Buffer([0x11,0x22,0x33,0x44,0x55,0x66]);
<Buffer 11 22 33 44 55 66>
> buffer.readUInt8(0);
17
> buffer.readUInt8(1);
34
> buffer.readUInt8(2);
51
> buffer.readUInt8(3);
68
> buffer.readUInt8(4);
85
> buffer.readUInt8(5);
102
> buffer.readUInt8(6);
RangeError: index out of range
    at checkOffset (buffer.js:615:11)
    at Buffer.readUInt8 (buffer.js:653:5)
    at repl:1:8
    at REPLServer.defaultEval (repl.js:262:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:431:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:211:10)
>

2、错误原因

超出索引值范围


3、解决办法

由于索引值可以为0、1、2、3、4、5,不能超过5,所以不能出现buffer.readUInt8(6);

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

🍍 "user" store installed 🆕 request.js:91 original config data: {account: 'xh_root', password: 'xh_root123456'} request.js:93 encoded config data: Uint8Array(24) [18, 7, 120, 104, 95, 114, 111, 111, 116, 26, 13, 120, 104, 95, 114, 111, 111, 116, 49, 50, 51, 52, 53, 54, buffer: ArrayBuffer(8192), byteLength: 24, byteOffset: 0, length: 24, Symbol(Symbol.toStringTag): 'Uint8Array'] request.js:145 original res: {data: '\x12\f登录成功(\x012\x07400|401\b\x01\x1A�\x02eyJhbGciOiJIUzI1NiIsInR5cCI6…yglGhWWF7HXX7rdBv_87naAMwqYsIRcBo"\x0EXHIOTLan/v1;v3', status: 200, statusText: 'OK', headers: {…}, config: {…}, …} request.js:183 binaryData: Uint8Array(396) [18, 12, 231, 153, 187, 229, 189, 149, 230, 136, 144, 229, 138, 159, 40, 1, 50, 7, 52, 48, 48, 124, 52, 48, 49, 8, 1, 26, 239, 191, 189, 2, 101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 73, 85, 122, 73, 49, 78, 105, 73, 115, 73, 110, 82, 53, 99, 67, 73, 54, 73, 107, 112, 88, 86, 67, 74, 57, 46, 101, 121, 74, 72, 99, 109, 57, 49, 99, 70, 66, 108, 99, 109, 49, 112, 99, 51, 78, 112, 98, 50, 52, 105, 79, 105, 73, 105, 76, 67, 74, …] request.js:184 binaryData length: 396 request.js:199 Protobuf decoding error: RangeError: index out of range: 32 + 5201903 > 396 at indexOutOfRange (protobufjs.js?v=13cddb31:1029:14) at Reader.read_bytes [as bytes] (protobufjs.js?v=13cddb31:1162:15) at Reader.read_string [as string] (protobufjs.js?v=13cddb31:1173:24) at Type.UserReply$decode [as decode] (eval at Codegen (protobufjs.js?v=13cddb31:1404:29), <anonymous>:21:13) at Type.decode_setup [as decode] (protobufjs.js?v=13cddb31:2814:27) at request.js:187:41 (anonymous) @ request.js:199 Promise.then request @ axios.js?v=13cddb31:1601 wrap @ axios.js?v=13cddb31:11 login @ login.js:24 (anonymous) @ user.js:26 login @ user.js:25 (anonymous) @ pinia.js?v=13cddb31:1103 store.<computed> @ pinia.js?v=13cddb31:784 (anonymous) @ login.vue:94 validateField @ element-plus.js?v=13cddb31:6254 await in validateField validate @ element-plus.js?v=13cddb31:6227 handleLogin @ login.vue:79 cache.<computed>.cache.<computed> @ chunk-BWSODKTZ.js?v=13cddb31:11500 callWithErrorHandling @ chunk-BWSODKTZ.js?v=13cddb31:1650 callWithAsyncErrorHandling @ chunk-BWSODKTZ.js?v=13cddb31:1657 emit @ chunk-BWSODKTZ.js?v=13cddb31:2124 (anonymous) @ chunk-BWSODKTZ.js?v=13cddb31:8123 handleClick @ element-plus.js?v=13cddb31:11416 callWithErrorHandling @ chunk-BWSODKTZ.js?v=13cddb31:1650 callWithAsyncErrorHandling @ chunk-BWSODKTZ.js?v=13cddb31:1657 invoker @ chunk-BWSODKTZ.js?v=13cddb31:10503 user.js:27 res:  登录成功(2400|401�eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJHcm91cFBlcm1pc3Npb24iOiIiLCJQZXJtaXNzaW9uVmFsdWUiOiIiLCJVc2VyUGVybWlzc2lvbiI6IjQwMHw0MDEiLCJhZG1pbiI6dHJ1ZSwiYXVkIjoiWEhJT1RMYW4iLCJleHAiOjE3NjI0MTg1OTAsImlzcyI6InhoaW90c2VydmVyIiwianRpIjoiezZjNjBmNmM5LTNjZGYtNDZhMC1iNDJlLWEwYjJmODMwMTQ5Mn0iLCJzdWIiOiJ4aF9yb290In0.mpNaDrlMdCyglGhWWF7HXX7rdBv_87naAMwqYsIRcBo"XHIOTLan/v1;v3 user.js:28 res.token: undefined prepare.js:1 🍍 "app" store installed 🆕 prepare.js:1 🍍 "permission" store installed 🆕 prepare.js:1 🍍 "tags-view" store installed 🆕
11-06
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值