Skip to content

Commit 96ecdeb

Browse files
committed
fix(python): keep original spec and avoid crash when no width/height
Signed-off-by: glowies <[email protected]>
1 parent 60eef14 commit 96ecdeb

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/python/py_imagebuf.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,18 +255,16 @@ py::bytes
255255
ImageBuf_repr_png(const ImageBuf& self)
256256
{
257257
ImageSpec original_spec = self.spec();
258-
ImageSpec new_spec (
259-
original_spec.width,
260-
original_spec.height,
261-
original_spec.nchannels,
262-
TypeDesc::UINT8
263-
);
258+
259+
if (original_spec.width < 1 || original_spec.height < 1) {
260+
return py::bytes();
261+
}
264262

265263
std::vector<unsigned char> file_buffer; // bytes will go here
266264
Filesystem::IOVecOutput file_vec (file_buffer); // I/O proxy object
267265

268266
std::unique_ptr<ImageOutput> out = ImageOutput::create ("temp.png", &file_vec);
269-
out->open ("temp.png", new_spec);
267+
out->open ("temp.png", original_spec);
270268
self.write(out.get());
271269
out->close ();
272270

0 commit comments

Comments
 (0)