Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html>
<head>
<style>
@page {
size: 40px 40px;
margin: 0;
padding:0;
}
body {
background-color:red;
}
</style>
</head>
<body>
<div>a<img src="data:image/png;base64,iVB"/>b</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,18 @@ public void testIssue482InfiniteLoopTable() throws IOException {
}));
}

/**
* Ensure there is no NPE exception launched if the decoding of an image fail (base64 case).
*
* See issue https://github.com/danfickle/openhtmltopdf/issues/474
*
* @throws IOException
*/
@Test
public void testIssue474NpeImageDecoding() throws IOException {
assertTrue(vt.runTest("issue-474-npe-image-decoding"));
}

// TODO:
// + Elements that appear just on generated overflow pages.
// + content property (page counters, etc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ public ImageResource getImageResource(String uriStr) {

if (ImageUtil.isEmbeddedBase64Image(uriResolved)) {
resource = loadEmbeddedBase64ImageResource(uriResolved);
_outputDevice.realizeImage((PdfBoxImage) resource.getImage());
_imageCache.put(uriResolved, resource);
// see issue 474: getImage can be null, as the loading of the embedded base64 resource may fail.
if (resource.getImage() != null) {
_outputDevice.realizeImage((PdfBoxImage) resource.getImage());
_imageCache.put(uriResolved, resource);
}
} else {
InputStream is = openStream(uriResolved);

Expand Down