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

How to set max array length (maxArrayLength)? #961

Open
FreePhoenix888 opened this issue Mar 8, 2024 · 1 comment
Open

How to set max array length (maxArrayLength)? #961

FreePhoenix888 opened this issue Mar 8, 2024 · 1 comment
Labels
bug This issue identifies a malfunction

Comments

@FreePhoenix888
Copy link

FreePhoenix888 commented Mar 8, 2024

Description

How to set max array length (maxArrayLength)?

Code I run

import debug from 'debug'
const log = debug('myApp');

const justArray = new Array(10_000).fill(0);
log({justArray})

const objWithNestedLongArray = {
  nestedArray: justArray
}

log({ objWithNestedLongArray})

How I have tried to set max array length

DEBUG="myApp" DEPTH_MAX_ARRAY_LENGTH="30000" bun run index.ts 
DEBUG="myApp" DEPTH_MAXARRAYLENGTH="30000" bun run index.ts
DEBUG="myApp" DEPTH_maxArrayLength="30000" bun run index.ts

Result

Despite all the 3 methods I have tried to set max array length I get the same result:

  myApp {
  myApp   objWithNestedLongArray: {
  myApp     nestedArray: [
  myApp       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp       0, 0, 0, 0,
  myApp       ... 9900 more items
  myApp     ]
  myApp   }
  myApp } +0ms
  myApp {
  myApp   justArray: [
  myApp     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  myApp     0, 0, 0, 0,
  myApp     ... 9900 more items
  myApp   ]
  myApp } +15ms

Additional Info

https://www.npmjs.com/package/debug#environment-variables chapter in documentation tells that by using DEBUG_ I can set Options object that gets used with %o/%O formatters like DEBUG_DEPTH, do I misunderstand that part?

@Qix-
Copy link
Member

Qix- commented Mar 9, 2024

No you don't misunderstand, in theory that should work. Have you tried setting it to 0? Otherwise, have you tried doing simply DEBUG_DEPTH=null?

I looked at the code again and wow, we shouldn't be doing it the way we are. It's not very robust / potentially not very secure (though I struggle to think of an e.g. prototype injection attack where we could exploit it).

If you can't figure it out then let me know, I'll mark this as a bug in the meantime.

@Qix- Qix- added the bug This issue identifies a malfunction label Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue identifies a malfunction
Development

No branches or pull requests

2 participants