Skip to content

Infinite loop in encode.js #2098

Open
@ajmeese7

Description

@ajmeese7

New Issue Checklist

Issue Description

The encode function is called recursively without a ceiling, causing the entire service to crash with no hint as to the originating call, even with VERBOSE=1 enabled. All I know is that the error is thrown from this line:

if (value && typeof value === 'object') {
  const output = {};
  for (const k in value) {
+   output[k] = encode(value[k], disallowObjects, forcePointers, seen, offline);
  }
  return output;
}

Steps to reproduce

Unsure, inherited legacy code and there is no hint as to which network call is causing this issue.

Actual Outcome

Program errors out without any hint as to where the error is coming from.

Expected Outcome

The function to execute properly. Two possible improvements to the library come to mind:

  1. Give further context about where the error is coming from
  2. Have a limit on the number of calls within the function and truncate after the limit is hit, giving a warning in the console but not causing the program to error out

Environment

Server

  • Parse Server version: 7.0.0
  • Operating system: node:18 Docker image
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Local

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: 5.9.2
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): Local

Client

  • Parse JS SDK version: 5.0.0

Logs

An uncaught exception occurred: Maximum call stack size exceededStack Trace:
RangeError: Maximum call stack size exceeded
    at encode (/api/node_modules/.pnpm/[email protected]/node_modules/parse/lib/node/encode.js:23:16)
    at /api/node_modules/.pnpm/[email protected]/node_modules/parse/lib/node/encode.js:61:14
    at Array.map (<anonymous>)
    at encode (/api/node_modules/.pnpm/[email protected]/node_modules/parse/lib/node/encode.js:60:18)
    at encode (/api/node_modules/.pnpm/[email protected]/node_modules/parse/lib/node/encode.js:67:19)
    at encode (/api/node_modules/.pnpm/[email protected]/node_modules/parse/lib/node/encode.js:67:19)
    at encode (/api/node_modules/.pnpm/[email protected]/node_modules/parse/lib/node/encode.js:67:19)
    at encode (/api/node_modules/.pnpm/[email protected]/node_modules/parse/lib/node/encode.js:67:19)
    at encode (/api/node_modules/.pnpm/[email protected]/node_modules/parse/lib/node/encode.js:67:19)

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions