mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
https://mozilla.github.io/nunjucks/
BSD 2-Clause "Simplified" License
8.48k stars 634 forks source link

Cannot read properties of null (reading 'type') #1454

Open manunio opened 7 months ago

manunio commented 7 months ago

Description

While Fuzzing locally using jazzer.js parser.parse() threw TypeError: Cannot read properties of null (reading 'type')

Steps to reproduce

❯ cat test.js
const parser = require('./nunjucks/src/parser')
parser.parse('_•0]{{{{')
❯ node test.js
/home/maxx/dev/security/oss-fuzz-projects/nunjucks/nunjucks/src/parser.js:1162
      const type = this.peekToken().type;
                                   ^

TypeError: Cannot read properties of null (reading 'type')
    at Parser.parseAggregate (/home/maxx/dev/security/oss-fuzz-projects/nunjucks/nunjucks/src/parser.js:1162:36)
    at Parser.parsePrimary (/home/maxx/dev/security/oss-fuzz-projects/nunjucks/nunjucks/src/parser.js:1054:19)
    at Parser.parseAggregate (/home/maxx/dev/security/oss-fuzz-projects/nunjucks/nunjucks/src/parser.js:1180:26)
    at Parser.parsePrimary (/home/maxx/dev/security/oss-fuzz-projects/nunjucks/nunjucks/src/parser.js:1054:19)
    at Parser.parseUnary (/home/maxx/dev/security/oss-fuzz-projects/nunjucks/nunjucks/src/parser.js:1007:19)
    at Parser.parsePow (/home/maxx/dev/security/oss-fuzz-projects/nunjucks/nunjucks/src/parser.js:983:21)
    at Parser.parseMod (/home/maxx/dev/security/oss-fuzz-projects/nunjucks/nunjucks/src/parser.js:971:21)
    at Parser.parseFloorDiv (/home/maxx/dev/security/oss-fuzz-projects/nunjucks/nunjucks/src/parser.js:959:21)
    at Parser.parseDiv (/home/maxx/dev/security/oss-fuzz-projects/nunjucks/nunjucks/src/parser.js:947:21)
    at Parser.parseMul (/home/maxx/dev/security/oss-fuzz-projects/nunjucks/nunjucks/src/parser.js:935:21)

Node.js v21.1.0