Skip to content

Commit

Permalink
Add fallback to pretty print invalid UTF8 data.
Browse files Browse the repository at this point in the history
Malformed UTF8 data can cause the escaping code to fail. Capture the
failures and print out a hex version with error note.
  • Loading branch information
davidlehn committed Mar 17, 2022
1 parent 7928551 commit 2b1f368
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Forge ChangeLog
===============

## 1.3.0 - 2022-XXX

### Fixed
- [asn1] Add fallback to pretty print invalid UTF8 data.

## 1.2.1 - 2022-01-11

### Fixed
Expand Down
11 changes: 10 additions & 1 deletion lib/asn1.js
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,16 @@ asn1.prettyPrint = function(obj, level, indentation) {
}
rval += '0x' + forge.util.bytesToHex(obj.value);
} else if(obj.type === asn1.Type.UTF8) {
rval += forge.util.decodeUtf8(obj.value);
try {
rval += forge.util.decodeUtf8(obj.value);
} catch(e) {
if(e.message === 'URI malformed') {
rval +=
'0x' + forge.util.bytesToHex(obj.value) + ' (malformed UTF8)';
} else {
throw e;
}
}
} else if(obj.type === asn1.Type.PRINTABLESTRING ||
obj.type === asn1.Type.IA5String) {
rval += obj.value;
Expand Down

0 comments on commit 2b1f368

Please sign in to comment.