diff --git a/src/live2dcubismframework.ts b/src/live2dcubismframework.ts index ada25a8..adde886 100644 --- a/src/live2dcubismframework.ts +++ b/src/live2dcubismframework.ts @@ -16,7 +16,9 @@ import { Value } from './utils/cubismjson'; export function strtod(s: string, endPtr: string[]): number { let index = 0; - for (let i = 1; ; i++) { + // Bound the scan: once i exceeds s.length, substring clamps and a complete + // number never becomes NaN, so an unbounded loop never terminates. + for (let i = 1; i <= s.length; i++) { const testC: string = s.slice(i - 1, i); // 指数・マイナスの可能性があるのでスキップする diff --git a/src/utils/cubismjson.ts b/src/utils/cubismjson.ts index e87c5e9..e4251ff 100644 --- a/src/utils/cubismjson.ts +++ b/src/utils/cubismjson.ts @@ -390,8 +390,11 @@ export class CubismJson { case '8': case '9': { const afterString: string[] = new Array(1); // 参照渡しにするため - f = strtod(buffer.slice(i), afterString); - outEndPos[0] = buffer.indexOf(afterString[0]); + const numericSlice = buffer.slice(i); + f = strtod(numericSlice, afterString); + // afterString[0] が空だと indexOf('') は 0 を返し、パース位置が巻き戻る + const remainder = afterString[0] ?? ''; + outEndPos[0] = i + numericSlice.length - remainder.length; return new JsonFloat(f); } case '"':