Skip to content
This repository was archived by the owner on Apr 30, 2021. It is now read-only.

Commit 3793e8b

Browse files
author
Yevgeny Pats
authored
Merge pull request #11 from bookmoons/xml
Add xml fuzzer
2 parents e0ca034 + 1aef2ec commit 3793e8b

File tree

3 files changed

+196
-0
lines changed

3 files changed

+196
-0
lines changed

examples/xml/fuzz.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const xml2js = require('xml2js')
2+
3+
async function fuzz (bytes) {
4+
const string = String.fromCodePoint(...bytes)
5+
try {
6+
await xml2js.parseStringPromise(string)
7+
} catch (error) {
8+
if (!acceptable(error)) throw error
9+
}
10+
}
11+
12+
function acceptable (error) {
13+
return !!expected
14+
.find(message => error.message.startsWith(message))
15+
}
16+
17+
const expected = [
18+
'Non-whitespace before first tag',
19+
'Unencoded',
20+
'Unexpected end',
21+
'Invalid character',
22+
'Invalid attribute name',
23+
'Invalid tagname',
24+
'Unclosed root tag',
25+
'Attribute without value',
26+
'Forward-slash in opening tag',
27+
'Text data outside of root node',
28+
'Unquoted attribute value',
29+
'Unmatched closing tag',
30+
'No whitespace between attributes',
31+
'Unexpected close tag'
32+
]
33+
34+
exports.fuzz = fuzz

examples/xml/package-lock.json

Lines changed: 153 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/xml/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "xml2js-fuzz",
3+
"version": "1.0.0",
4+
"main": "fuzz.js",
5+
"license": "ISC",
6+
"dependencies": {
7+
"xml2js": "^0.4.22"
8+
}
9+
}

0 commit comments

Comments
 (0)