Skip to content

Commit 2b1f368

Browse files
committed
Add fallback to pretty print invalid UTF8 data.
Malformed UTF8 data can cause the escaping code to fail. Capture the failures and print out a hex version with error note.
1 parent 7928551 commit 2b1f368

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Forge ChangeLog
22
===============
33

4+
## 1.3.0 - 2022-XXX
5+
6+
### Fixed
7+
- [asn1] Add fallback to pretty print invalid UTF8 data.
8+
49
## 1.2.1 - 2022-01-11
510

611
### Fixed

lib/asn1.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,16 @@ asn1.prettyPrint = function(obj, level, indentation) {
13911391
}
13921392
rval += '0x' + forge.util.bytesToHex(obj.value);
13931393
} else if(obj.type === asn1.Type.UTF8) {
1394-
rval += forge.util.decodeUtf8(obj.value);
1394+
try {
1395+
rval += forge.util.decodeUtf8(obj.value);
1396+
} catch(e) {
1397+
if(e.message === 'URI malformed') {
1398+
rval +=
1399+
'0x' + forge.util.bytesToHex(obj.value) + ' (malformed UTF8)';
1400+
} else {
1401+
throw e;
1402+
}
1403+
}
13951404
} else if(obj.type === asn1.Type.PRINTABLESTRING ||
13961405
obj.type === asn1.Type.IA5String) {
13971406
rval += obj.value;

0 commit comments

Comments
 (0)