mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-18 11:42:47 +00:00
[lua] Fix crash using invalid width/height in Image()
This commit is contained in:
parent
76ef344f49
commit
c7b3e15d05
@ -124,7 +124,13 @@ int Image_new(lua_State* L)
|
|||||||
spec.setHeight(h);
|
spec.setHeight(h);
|
||||||
spec.setColorMode((doc::ColorMode)colorMode);
|
spec.setColorMode((doc::ColorMode)colorMode);
|
||||||
}
|
}
|
||||||
|
if (spec.width() < 1) spec.setWidth(1);
|
||||||
|
if (spec.height() < 1) spec.setHeight(1);
|
||||||
doc::Image* image = doc::Image::create(spec);
|
doc::Image* image = doc::Image::create(spec);
|
||||||
|
if (!image) {
|
||||||
|
// Invalid spec (e.g. width=0, height=0, etc.)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
doc::clear_image(image, spec.maskColor());
|
doc::clear_image(image, spec.maskColor());
|
||||||
push_new<ImageObj>(L, image);
|
push_new<ImageObj>(L, image);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite Document Library
|
// Aseprite Document Library
|
||||||
// Copyright (c) 2018 Igara Studio S.A.
|
// Copyright (c) 2018-2020 Igara Studio S.A.
|
||||||
// Copyright (c) 2001-2016 David Capello
|
// Copyright (c) 2001-2016 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
@ -56,6 +56,10 @@ Image* Image::create(PixelFormat format, int width, int height,
|
|||||||
Image* Image::create(const ImageSpec& spec,
|
Image* Image::create(const ImageSpec& spec,
|
||||||
const ImageBufferPtr& buffer)
|
const ImageBufferPtr& buffer)
|
||||||
{
|
{
|
||||||
|
ASSERT(spec.width() >= 1 && spec.height() >= 1);
|
||||||
|
if (spec.width() < 1 || spec.height() < 1)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
switch (spec.colorMode()) {
|
switch (spec.colorMode()) {
|
||||||
case ColorMode::RGB: return new ImageImpl<RgbTraits>(spec, buffer);
|
case ColorMode::RGB: return new ImageImpl<RgbTraits>(spec, buffer);
|
||||||
case ColorMode::GRAYSCALE: return new ImageImpl<GrayscaleTraits>(spec, buffer);
|
case ColorMode::GRAYSCALE: return new ImageImpl<GrayscaleTraits>(spec, buffer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user