tapmodo / node-ldif

Nodejs LDIF (LDAP Data Interchange Format) parser based on RFC2849
9 stars 7 forks source link

Max callstack exceeded in parser #4

Open mvayngrib opened 7 years ago

mvayngrib commented 7 years ago

trying to parse CSCA master lists (country signing certificates) from https://pkddownloadsg.icao.int/ (need to go through captcha at the bottom to get to the download)

const ldif = require('ldif')
const file = ldif.parseFile('./CSCA Master Lists.ldif')
      if (peg$c112.test(input.charAt(peg$currPos))) {
                   ^

RangeError: Maximum call stack size exceeded
    at RegExp.exec (native)
    at RegExp.test (native)
    at peg$parseBASE64_CHAR (/Users/tenaciousmv/Code/verifypassport/node_modules/ldif/lib/parser.js:2463:20)
    at peg$parseBASE64_STRING (/Users/tenaciousmv/Code/verifypassport/node_modules/ldif/lib/parser.js:2439:12)
    at peg$parsebase64_value_spec (/Users/tenaciousmv/Code/verifypassport/node_modules/ldif/lib/parser.js:2146:12)
    at peg$parsebase64_value_spec (/Users/tenaciousmv/Code/verifypassport/node_modules/ldif/lib/parser.js:2152:18)
    at peg$parsebase64_value_spec (/Users/tenaciousmv/Code/verifypassport/node_modules/ldif/lib/parser.js:2152:18)
    at peg$parsebase64_value_spec (/Users/tenaciousmv/Code/verifypassport/node_modules/ldif/lib/parser.js:2152:18)
    at peg$parsebase64_value_spec (/Users/tenaciousmv/Code/verifypassport/node_modules/ldif/lib/parser.js:2152:18)
    at peg$parsebase64_value_spec (/Users/tenaciousmv/Code/verifypassport/node_modules/ldif/lib/parser.js:2152:18)
mvayngrib commented 7 years ago

@tapmodo your ldif-stream package parses it though :) I probably prefer a stream interface anyway

tapmodo commented 7 years ago

this might be a difficult problem to solve. i am not an expert on the PEG parser generator, but i imagine a very large file could create a lot of recursion, when trying to parse the entire file at once. the maximum stack size can be increased, but clearly it's an inefficient approach. glad to hear the ldif-stream package solved the problem. for a lot of data i also would prefer a stream interface.