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

TypeError: Cannot read property 'dimensions' of undefined #1856

Closed
SpeckyYT opened this issue May 13, 2020 · 2 comments
Closed

TypeError: Cannot read property 'dimensions' of undefined #1856

SpeckyYT opened this issue May 13, 2020 · 2 comments
Labels

Comments

@SpeckyYT
Copy link

OS: Windows 7
NodeJS Version: v13.12.0
MathJS Version: v7.0.0 (tested with v6.6.5 too)

I created a prototype for the Object type.

Object.prototype.test = function(){}; // example

But when I require 'mathjs' with that custom prototype, it returns the following error:

TypeError: Cannot read property 'dimensions' of undefined
    at createUnitClass.isClass (%mainpath%\node_modules\mathjs\lib\type\unit\Unit.js:3661:33)
    at assertAndCreate (%mainpath%\node_modules\mathjs\lib\utils\factory.js:49:12)
    at Object.<anonymous> (%mainpath%\node_modules\mathjs\lib\entry\pureFunctionsAny.generated.js:1209:61)
    at Module._compile (internal/modules/cjs/loader.js:1147:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (%mainpath%\node_modules\mathjs\lib\entry\mainAny.js:53:25)
    at Module._compile (internal/modules/cjs/loader.js:1147:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (%mainpath%\node_modules\mathjs\main\es5\index.js:1:18)
    at Module._compile (internal/modules/cjs/loader.js:1147:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (%mainpath%\src\commands\utilities\math.js:10:22)
    at Module._compile (internal/modules/cjs/loader.js:1147:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (internal/modules/cjs/helpers.js:72:18)

I tried to delete the prototype, and when requiring 'mathjs', it doesn't return any error, but I would need to have those custom prototypes.

I tried to reinstall the 'mathjs' module, but without any success

#535

@josdejong
Copy link
Owner

josdejong commented May 18, 2020

Thanks for bringing this up @SpeckyYT . Turns out the library is not robust against Object prototype pollution. I've made a fix for this in #1860, awaiting to see if all tests pass.

Note that it's good practice to never extend the Object prototype! It can very easily break libraries (like you've seen with mathjs), and messing with the Object prototype is a technique often used in attacks. To write a proper unit test to test this, I had to disable eslint for the test because it throws an error when extending the Object prototype.

@josdejong
Copy link
Owner

Fix is published in v7.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants