Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEP0005: Buffer() is deprecated due to security and usability issues #3

Closed
Neved4 opened this issue Aug 15, 2023 · 1 comment · Fixed by #4
Closed

DEP0005: Buffer() is deprecated due to security and usability issues #3

Neved4 opened this issue Aug 15, 2023 · 1 comment · Fixed by #4

Comments

@Neved4
Copy link
Contributor

Neved4 commented Aug 15, 2023

That function was deprecated as per nodejs/node#4660.

While manually installing the extension, the following warning appears:

code --install-extension ilatex.vsix
Installing extensions...
(node:46741) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues.
Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `Electron --trace-deprecation ...` to show where the warning was created)
Extension 'ilatex.vsix' was successfully installed.

With --trace-deprecation we can locate where the deprecated function is being used:

Installing extensions...
(node:47479) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues.
Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
    at showFlaggedDeprecation (node:buffer:191:11)
    at new Buffer (node:buffer:275:3)
    at /Visual Studio Code.app/Contents/Resources/app/node_modules.asar/fd-slicer/index.js:109:18
    at pendGo (/Visual Studio Code.app/Contents/Resources/app/node_modules.asar/pend/index.js:54:3)
    at onCb (/Visual Studio Code.app/Contents/Resources/app/node_modules.asar/pend/index.js:41:7)
    at /Visual Studio Code.app/Contents/Resources/app/node_modules.asar/fd-slicer/index.js:31:7
    at FSReqCallback.wrapper [as oncomplete] (node:fs:677:5)
Extension 'ilatex.vsix' was successfully installed.

The following is the line that's causing this:

input = new Buffer(literals);

To achieve the migration, we need to change its syntax:

new Buffer(string)   // Old
Buffer.from(string)  // New

In the codebase:

-input = new Buffer(literals);
+input = Buffer.from(literals);

Additionally, i-LaTeX is using version 2.3.200 of pdf.js:

var pdfjsVersion = '2.3.200';

Last release of pdf.js currently is 3.9.179 and lacks this issue, so upgrading the dependency is another option to be considered.

@Daru13
Copy link
Collaborator

Daru13 commented Jan 30, 2024

Sorry for the slow answer, and thank you for suggesting this fix/update! :)

After merging your fix, I tried updating PDF.js to the current last version (4.0.379), but it seems like they switched to ES modules starting from major version 4, which are—as far as I know—not readily compatible with the architecture of i-LaTeX's webview. However, the last release before that change, version 3.11.174, seems to work just fine. 671cae1 updates the code to use this version instead, which, indeed, does not seem to instantiate any Buffer object using new.

Daru13 added a commit that referenced this issue Jan 30, 2024
This includes fixes for GitHub issues #1 to #3, which are resolved by the last few commits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants