Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/live2dcubismframework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

// 指数・マイナスの可能性があるのでスキップする
Expand Down
7 changes: 5 additions & 2 deletions src/utils/cubismjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '"':
Expand Down