b0yediti0n
b0yediti0n14h ago

Deno Pointer FFI error, malloc(): invalid size (unsorted)

Some runitime im my software i have the error, some me help to fin the line with error?
libName = libName.toUpperCase();

const args = [ ]
params.forEach(param => {
switch(typeof param){
case "string":
args.push(this.enc.encode(param + '\0'))
break;
default:
args.push(param)
}
});

const DEFAULT_LENGTH = 2792; // Tem que ser divisivel por 8
const outPtrs = new ArrayBuffer(8 + DEFAULT_LENGTH); // A soma deve dar um valor sem 0 na casa decimal final?
const sResposta = new Uint8Array(outPtrs, 8, DEFAULT_LENGTH);
const esTamanho = new Uint8Array(outPtrs, 0, 8);
// aloca o valor default para os espaço tamanho do buffer
const esTamanhoView = new Uint16Array(outPtrs, 0, 4);
esTamanhoView[0] = DEFAULT_LENGTH;

args.push(sResposta)
args.push(esTamanho)

type typSymbolFFICall = { symbols : { [Key: string]: CallableFunction } }

const libModule = this?.[libName as keyof controleFiscal] as typSymbolFFICall;
libModule!.symbols[method](...args) == 0

new TextDecoder().decode(sResposta.subarray(0, esTamanhoValue));
libName = libName.toUpperCase();

const args = [ ]
params.forEach(param => {
switch(typeof param){
case "string":
args.push(this.enc.encode(param + '\0'))
break;
default:
args.push(param)
}
});

const DEFAULT_LENGTH = 2792; // Tem que ser divisivel por 8
const outPtrs = new ArrayBuffer(8 + DEFAULT_LENGTH); // A soma deve dar um valor sem 0 na casa decimal final?
const sResposta = new Uint8Array(outPtrs, 8, DEFAULT_LENGTH);
const esTamanho = new Uint8Array(outPtrs, 0, 8);
// aloca o valor default para os espaço tamanho do buffer
const esTamanhoView = new Uint16Array(outPtrs, 0, 4);
esTamanhoView[0] = DEFAULT_LENGTH;

args.push(sResposta)
args.push(esTamanho)

type typSymbolFFICall = { symbols : { [Key: string]: CallableFunction } }

const libModule = this?.[libName as keyof controleFiscal] as typSymbolFFICall;
libModule!.symbols[method](...args) == 0

new TextDecoder().decode(sResposta.subarray(0, esTamanhoValue));
1 Reply
AapoAlas
AapoAlas11h ago
It's hard to say much anything here since there's no way to know which function you're calling or what its parameters are, but the error probably comes from writing past the ends of a buffer which then messes up malloc. Your code is assuming that every function is always called with parameters (a, b, ..., d) and the corresponding FFI call is (a, b, ..., d, sReposta, esTamanho). If that's not the case then you'll be writing over various ends of various buffers.

Did you find this page helpful?