Jimp.read creating error - zlib binding closed - javascript

I am working using Node and Discord.js, making edits to the source code of a Discord bot for a client. As such I won't be able to provide the full source files as the vast majority of the code isn't mine and I'd rather not release the client's code just in case - but I'll be posting the snippets written by me that are relevant to the question.
The task involves making the bot generate an image highlighting the 'daily' items in the Fortnite game shop. Basically, a background/template image, which will have the images of various shop items overlayed onto boxes in the template image. To accomplish this, I've been attempting to use Jimp for the image manipulation/generation involved. However, I've run across a strange issue that only seems to be a problem when the images came from the API that provides the Fortnite item pngs.
This API returns (among other things) a URL to the image, which was what I initially tried to use to read from with Jimp. (Note that I can't actually provide any links to the API docs as it's in a closed beta; I only have access to it because the client gave me their token so I could work on it.) Jimp.read is meant to take an img URL that it processes into a Jimp image - and this seems to work fine when I use an image URL from any other source. When feeding it the URL from this API, though, it causes an exception which console.logs as:
AssertionError [ERR_ASSERTION]: zlib binding closed
(followed by the rest of a stack trace, which I'll post in full down below).
I've been beating my head against a wall for several hours now trying to break through this, Googling, trying to create workarounds, try out alternative libraries, but have still not been able to get anywhere. I tried loading the image into a Buffer and feeding that into Jimp.read, but get the exact same error, word for word. Tried using the new Jimp( ... ) constructor instead but still didn't work.
I've also been Googling to try and find an answer but the zlib binding closed error seems to be extremely uncommon and there were very few mentions of it in any context, and no mentions of it in relation to Jimp that I could find. Googling "zlib binding closed" within quotes provided me only 19 results period. If nothing else, if anyone knows what this error means, that would help me have a better idea where to look to fix it.
I've tried looking into alternatives to the Jimp library, but as far as JavaScript image manipulating libraries go, the Canvas API requires a DOM object and Caman I just couldn't get to install.
I don't generally ask things on StackOverflow but I couldn't find instances of this problem anywhere. Possible solutions or even just explanations of what the error could mean would be extremely helpful, also if anyone has suggestions for a good alternative to Jimp in the case I can't fix this.
(Code snippets/stack traces below, I probably missed some important stuff since I'm tired and completely brainfried from working on this, so let me know if you need anything else from me)
URL Attempt:
Jimp.read("https://image.fnbr.co/outfit/5b90ec38262b40c2dcc98379/icon.png")
.then(image => {
message.channel.send("jimp", {
file: image
});
})
.catch(err => {
console.log(err);
});") // Should just return a URL string
.then(image => {
message.channel.send("jimp", {
file: image
});
})
.catch(err => {
console.log(err);
});
Buffer Attempt:
request.get("https://image.fnbr.co/outfit/5b90ec38262b40c2dcc98379/icon.png", function(error, response, body) {
if (!error && response.statusCode == 200) {
var buffer = new Buffer(body);
Jimp.read(buffer)
.then(image => {
message.channel.send("jimp", {
file: image
});
})
.catch(err => {
console.log(err);
});
} else {
console.log("8(");
}
});
^ Ultimately the above will be getting the image URLs based on the 'daily' results from the shop but for now I'm just trying to get them to work on a hard-coded URL. All URLs from that API follow the same format as the one used here.
Full console.log(err) Console Output:
{ AssertionError [ERR_ASSERTION]: zlib binding closed
at Inflate._processChunk (C:\Users\(user)\Documents\dev\(project)\node_modules\pngjs\lib\sync-inflate.js:108:3)
at zlibBufferSync (C:\Users\(user)\Documents\dev\(project)\node_modules\pngjs\lib\sync-inflate.js:151:17)
at inflateSync (C:\Users\(user)\Documents\dev\(project)\node_modules\pngjs\lib\sync-inflate.js:155:10)
at module.exports (C:\Users\(user)\Documents\dev\(project)\node_modules\pngjs\lib\parser-sync.js:79:20)
at Object.exports.read [as image/png] (C:\Users\(user)\Documents\dev\(project)\node_modules\pngjs\lib\png-sync.js:10:10)
at Jimp.parseBitmap (C:\Users\(user)\Documents\dev\(project)\node_modules\#jimp\core\dist\utils\image-bitmap.js:117:53)
at new Jimp (C:\Users\(user)\Documents\dev\(project)\node_modules\#jimp\core\dist\index.js:425:32)
at _construct (C:\Users\(user)\Documents\dev\(project)\node_modules\#jimp\core\dist\index.js:100:393)
at C:\Users\(user)\Documents\dev\(project)\node_modules\#jimp\core\dist\index.js:885:5
at Promise (<anonymous>)
generatedMessage: false,
name: 'AssertionError [ERR_ASSERTION]',
code: 'ERR_ASSERTION',
actual: undefined,
expected: true,
operator: '==',
methodName: 'constructor' }
Managing packages with npm, running from a Windows computer.

I was having the same issue.
In my case I was testing with node 10.15.3 but when I pkged my app, the node version embedded was on version 8. Since ZLIB is not available in that version, the assert failed. That is the reason why I was seeing the error.

Related

'No frame for given id found' in puppetter

i am using puppetter for web scrapping ;
matchesLinks is an array that contains urls of some games.
my code looks like :
for (let i = 0; i < matchesLinks.length; i++) {
await page.goto(matchesLinks[i]);
await page.goto(matchesLinks[i]);
await new Promise((r) => setTimeout(r, 6000));
}
after going to 1 or 2 URL i get error: originalMessage: 'No frame for given id found'
anyone can help my why i am getting this error
I have been trying to solve the issue since 3 days now.. no luck at all..
Though the issue disappears completely if you set "headless: true" at browser's launch options.. So this issue is only associated with "headless: false" setting.
For those who try to help. The issue happens when using "page.goto" to access a website that have iframes, and redirect requests (Trying to abort those requests, or waituntil domcontentloaded won't solve the issue if you were wondering). E.g. it happens every time when trying to access "https://www.whatismyip.com/"
You might be facing the issue described here: https://github.com/puppeteer/puppeteer/pull/7848
You may try to downgrade puppeteer version to 11.0.0 as a workaround
EDIT: The fix has most likely been released. Consider upgrading the puppeteer.

Render PDF in Forge Viewer with PDF Extension - pdf.worker.js throws warning

While trying to render a PDF, which gets served through our own API, the pdf.worker.js throws the following warning and the rendered PDF always keeps being completely white.
And I only see this (it's a wide PDF, but gets correctly rendered within the Demo):
Our Client application is served with angular, however I could not totally encapsulate the problem. With a simple and new angular application I was able to render a PDF File, served from our API but in my bigger client application the error above keeps occurring and I don't know why.
I'm using this Code to load the PDF, which inspired by this GitHub and this Blog Entry from Autodesk.
Autodesk.Viewing.Initializer({ env: 'Development', useADP: false }, () => {
const viewer = new Autodesk.Viewing.GuiViewer3D(
document.getElementById('forgeViewer'),
);
viewer.start();
const url =
'http://api.pdfFileToRender.pdf';
viewer.loadExtension('Autodesk.PDF').then(() => {
viewer.loadModel(
url,
{},
model => {
console.error('Success: ', model);
},
(errorCode, errorMessage, errorArgs) => {
console.error('Error Code: ', errorCode);
console.error('Error Msg: ', errorMessage);
console.error('Error Args: ', errorArgs);
},
);
viewer.loadExtension('Autodesk.Viewing.MarkupsCore');
viewer.loadExtension('Autodesk.Viewing.MarkupsGui');
});
});
The loadModel Function also calls the onSuccessCallback and I see "Success" in my Console.
For me it is not possible to integrate the PDF Extension into my Client App. Does anyone know a solution or have a hint for this, I gladly appreciate it.
It is also important for me, that the PDFs are rendered locally and are not uploaded to any Forge API.
For serving the Client Application I'm using Angular 11.2.7 and Typescript 4.1.5. I'm loading the ForgeViewer with the Version 7.36.0 but the Problem occurs also with other Versions.
For anyone interested, I could figure it out. Our own application was defining array prototype functions. However this is a problem for pdf.js which get's used by the PDF Extension from Forge.
The root problem was by defining array prototype functions like this:
Array.prototype.myFunction = function(...) {...}
We had to either exclude our own array functions or write it that way:
Object.defineProperty(Array.prototype, 'myFunction', {value: function(...) {...})
So, if you application defines array prototype function, use Object.defineProperty or don't use them at all. This seems to solve the Issue. Cheers.

Exception from WebAuthn Authentication API with Yubikey

I'm working on adding WebAuthn support to a newly-minted web site and am running into a problem during the navigator.credentials.get() call. The client is Firefox 85.0 on Fedora 33. In case it matters, the server is Apache httpd on Fedora 33. The token is either a Yubikey 4 or a Yubikey 5NFC (the results are the same). This is the function making the API call. Obviously the credential IDs hard-coded here are for testing, not part of the final product:
function handleUserAuthenticationResponse(r) {
var cid1 = {type: "public-key", id: base64ToArrayBuffer("gL0Ig10uA2tn8L0kn2L9FoGqIPSrqvc1lLBwgQhcVDa200b1P94kPv94T6O1bDZyYRrfLbTrLRsubDxuYUxHCg==")};
var cid2 = {type: "public-key", id: base64ToArrayBuffer("tjW1RPqtAJm69I/qeV7eRFJx6h87J3NPeJ/hhbkjttcCc2BWHQ2v2nueoKBSGabw1eYsT8S+lhJv1l1mYWX+Uw==")};
var options = {
rpID: "http://localhost",
challenge: base64ToArrayBuffer(r.challenge),
allowCredentials: [cid1,cid2],
timeout: 60000
};
if (!window.PublicKeyCredential) {
throw new Error("Unable to access credentials interface");
}
navigator.credentials.get({"publicKey":options})
.then(assertion => handleTokenAssertion(assertion))
.catch(e => {console.log("Error fetching token assertion:",e);});
}
function base64ToArrayBuffer(base64) {
var binary_string = window.atob(base64);
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes.buffer;
}
function handleTokenAssertion(a) {
alert("Got an assertion!");
}
Everything seems to work, the Yubikey LED blinks, I press the touchpad, but then I get back an exception:
Error fetching token assertion: DOMException: An attempt was made to use an object that is not, or is no longer, usable
This seems to be a bit of a Firefox catch-all. It could indicate that the token doesn't match one of the allowedCredentials[], or perhaps other things. It's hard to tell. The FIDO2 credential on the Yubikey was created with fido2-cred(1) tool packaged with the libfido2 source. In this case the credentialId is from the fido2-cred -M output:
CuCEGL10uPhBmNCY4NsGaAz0gir/68UMGFQn0pfb6tc=
http://localhost
fido-u2f
WMSGBbi6CMINQvnkVRUYcYltDg3pgFlihvtzbRHuwBPipEEAAAAAAAAAAAAAAAAAAAAAAAAAAABAgL0Ig10uA2tn8L0kn2L9FoGqIPSrqvc1lLBwgQhcVDa200b1P94kPv94T6O1bDZyYRrfLbTrLRsubDxuYUxHCqUBAgMmIAEhWCA5itRRCBO0lnsztvPvI1waVZLBCZ1XMJjOvlN2oZmBCyJYILFaRjThs5Paj1sOp81iID1LpUBYHJhp4dizC0eI/RrE
gL0Ig10uA2tn8L0kn2L9FoGqIPSrqvc1lLBwgQhcVDa200b1P94kPv94T6O1bDZyYRrfLbTrLRsubDxuYUxHCg==
MEQCIFfs8PagKhNnDgzxfurVzdkTDVTT6ixKk0ak/2qrbSPUAiAf64w390rX1cyY58JgSC/Ac97w6TLcYKuqxOSn5lxV0g==
<long assertion certificate>
You can see the credentialId on line 5, and that it matches cid1 in the Javascript function. Furthermore, if I request an assertion from the token using this credentialId and all else identical (except the challenge) with fido2-assert -G, everything works fine: I get the assertion and it verifies correctly using fido2-assert -V.
Without a more meaningful diagnostic it's hard to know what to try, so I thought I would ask here and see if anyone has any hints. Perhaps I've made some basic error with either Javascript or the credentials API?
Thanks!
UPDATE: One possibility I thought might be worth trying was removing the scheme from the RP ID but that made no difference.
UPDATE: Looking at the firefox source code, the error is apparently NS_ERROR_DOM_INVALID_STATE_ERR, which covers several different situations but in this case is most likely a translation of U2F_ERROR_INVALID_STATE (in dom/webauthn/U2FHIDTokenManager.h). U2F_ERROR_INVALID_STATE, in turn, is defined in third_party/rust/authenticator/src/u2fhid-capi.h as a simple numerical value (3), with no indication of where the value came from. Perhaps it's defined by the underlying HID driver for the Yubikey, but it's not clear what driver that corresponds to. The hunt continues...
It turns out that the problem was indeed the format of the relying party ID. Based on example code from the net (which may have worked with other browsers or versions of the code?), I initially used the full scheme://domain format for the rpID (so in my code above, http://localhost), but it turns out that what's needed is just the domain (localhost). Modifying the rpID in this way allows the assertion process to succeed.
Initially I thought this did not work, but it turned out that I'd simply forgotten to commit the change. Having belatedly done that, it works.

The provided value 'moz-chunked-arraybuffer' is not a valid 'responseType

first time position a question here.
I am building an app with react native and expo and I have implemented an audio player that plays from an Icecast stream.
What I'm trying to achieve now is to get the metadata from the icecast stream so I have installed this library: https://github.com/ghaiklor/icecast-parser.
However, since it uses the http, events and stream modules form node I installed the following package to get them in react native: https://github.com/parshap/node-libs-react-native/, which managed to get the parsing library to work.
Now, the issue I'm having is that after the icecast-parser makes the http request for the stream, I get the following errors:
"The provided value 'moz-chunked-arraybuffer' is not a valid 'responseType'."
"The provided value 'ms-stream' is not a valid 'responseType'."
After reading https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequestResponseType I think the issue is that for some reason the response coming from the request is of that type which is what gives me the error.
So I'm trying to find if there's a way to transform it or make it work and was wondering if you had an idea or could point me in the right direction?
Here's the part of the code where the error occurs:
_makeRequest () {
const request = (this.getConfig('url').indexOf('https://') === 0) ?
https.request(this.getConfig('url')) : http.request(this.getConfig('url'));
request.setHeader('Icy-MetaData', '1');
request.setHeader('User-Agent', this.getConfig('userAgent'));
request.once('socket', function (socket) {
socket.once('end', this._onSocketEnd.bind(this));
}.bind(this));
console.log("I get here")
request.once('response', this._onRequestResponse.bind(this));
console.log("I don't get here")
request.once('error', this._onRequestError.bind(this));
request.end();
return this;
}
_onRequestResponse (response) {
console.log("not getting here")
const icyMetaInt = response.headers['icy-metaint'];
if (icyMetaInt) {
const reader = new StreamReader(icyMetaInt);
reader.on('metadata', metadata => {
this._destroyResponse(response);
this._queueNextRequest(this.getConfig('metadataInterval'));
this.emit('metadata', metadata);
});
response.pipe(reader);
this.emit('stream', reader);
} else {
this._destroyResponse(response);
this._queueNextRequest(this.getConfig('emptyInterval'));
this.emit('empty');
}
return this;
}
Apparently the issue comes from the fact that the library is built for nodeJS so even if I add a package that imports the required libraries into react-native, the code won't work. Tested this with a different parsing library that was built for nodeJS too.
try suppressing the warning using this line of code
LogBox.ignoreLogs
(['Warning: The provided value \'moz',
'Warning: The provided value \'ms-stream'
])

firebase functions get error stream removed onCreate firestore event

I'm worried about this error on firebase functions,
I have a sendgrid dispatch on this function:
exports.mailDealings = functions.firestore
.document('dealings/current').onCreate(event => {
// send mail
const msg = {...}
sgMail.send(msg);
})
.catch(result => {
console.error("sendgrid error", result);
});
I was able to execute with success before but on one call,
this function give me the error below:
{ Error: Stream removed
at ClientReadableStream._emitStatusIfDone (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:255:19)
at ClientReadableStream._receiveStatus (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:233:8)
at /user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:705:12 code: 2, metadata: Metadata { _internal_repr: {} } }
There should have an automatic retry for this error, right?
Or at least a method for turning this easy, like result.retry(1000)?
Same problem here (in many functions & randomly) since 3 / 4 days.
Apparently t disappears after deploy...for few minutes
Error: Stream removed
at ClientReadableStream._emitStatusIfDone (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:255:19)
at ClientReadableStream._receiveStatus (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:233:8)
at /user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:705:12
From the Google Groups discussion on this bug:
Hello all, Sebastian from the Firestore SDK team here. We believe this
issue is related to the recent update of the GRPC Client SDK and have
been running tests with GRPC 1.7.1. So far, we have not been able to
reproduce this issue with this older GRPC version.
#google-cloud/firestore is now at 0.10.1. If you update your
dependencies, you will be able to pull in this release.
Thanks for your patience.
Sebastian
This seems to have fixed the issue for me!

Categories

Resources