summaryrefslogtreecommitdiff
path: root/src/mbgl/sprite
diff options
context:
space:
mode:
authorzmiao <miao.zhao@mapbox.com>2020-04-07 16:30:30 +0300
committerGitHub <noreply@github.com>2020-04-07 16:30:30 +0300
commitbf4c7340f32c1e673e6a37b91fc65305757f52d1 (patch)
treec7871ff8901617b09d8a8d45b57334c2198b9b99 /src/mbgl/sprite
parent8986b558eb92e431c773b6033d8ae271eb71de00 (diff)
downloadqtlocation-mapboxgl-bf4c7340f32c1e673e6a37b91fc65305757f52d1.tar.gz
[build] Fix undefined behavour sanitizer (#16375)
* [build] Fix integer overflow runtime error for core part Temporarily remove circle ci UBSAN build precondition * [build] Enable all of the ubsans [build] Check runtime error [build] Update UBSAN_OPTION * [build] Add UBSAN blacklist [build] Ignore system libraries [build] Ignore vendor library * [build] Fix implicit conversion runtime error in core * [build] Fix division by zero runtime error * [build] Add unfixed error to ubsan blacklist * [build] Make UBSAN halt on error Revert "Temporary remove build precondition" * [build] Fix division by zero error * [build] Make UBSAN officially work without FIXME prefix * [build] Fix implicit conversion from int64_t to uint64_t * [build] Rename style test json file name * Address review findings
Diffstat (limited to 'src/mbgl/sprite')
-rw-r--r--src/mbgl/sprite/sprite_parser.cpp22
-rw-r--r--src/mbgl/sprite/sprite_parser.hpp8
2 files changed, 16 insertions, 14 deletions
diff --git a/src/mbgl/sprite/sprite_parser.cpp b/src/mbgl/sprite/sprite_parser.cpp
index ac0b7f91f1..997e363e50 100644
--- a/src/mbgl/sprite/sprite_parser.cpp
+++ b/src/mbgl/sprite/sprite_parser.cpp
@@ -17,21 +17,22 @@ namespace mbgl {
std::unique_ptr<style::Image> createStyleImage(const std::string& id,
const PremultipliedImage& image,
- const uint32_t srcX,
- const uint32_t srcY,
- const uint32_t width,
- const uint32_t height,
+ const int32_t srcX,
+ const int32_t srcY,
+ const int32_t width,
+ const int32_t height,
const double ratio,
const bool sdf,
style::ImageStretches&& stretchX,
style::ImageStretches&& stretchY,
const optional<style::ImageContent>& content) {
// Disallow invalid parameter configurations.
- if (width <= 0 || height <= 0 || width > 1024 || height > 1024 || ratio <= 0 || ratio > 10 ||
- srcX >= image.size.width || srcY >= image.size.height || srcX + width > image.size.width ||
- srcY + height > image.size.height) {
+ if (width <= 0 || height <= 0 || width > 1024 || height > 1024 || ratio <= 0 || ratio > 10 || srcX < 0 ||
+ srcY < 0 || srcX >= static_cast<int32_t>(image.size.width) || srcY >= static_cast<int32_t>(image.size.height) ||
+ srcX + width > static_cast<int32_t>(image.size.width) ||
+ srcY + height > static_cast<int32_t>(image.size.height)) {
Log::Error(Event::Sprite,
- "Can't create image with invalid metrics: %ux%u@%u,%u in %ux%u@%sx sprite",
+ "Can't create image with invalid metrics: %dx%d@%d,%d in %ux%u@%sx sprite",
width,
height,
srcX,
@@ -42,10 +43,11 @@ std::unique_ptr<style::Image> createStyleImage(const std::string& id,
return nullptr;
}
- PremultipliedImage dstImage({width, height});
+ const Size size(static_cast<uint32_t>(width), static_cast<uint32_t>(height));
+ PremultipliedImage dstImage(size);
// Copy from the source image into our individual sprite image
- PremultipliedImage::copy(image, dstImage, {srcX, srcY}, {0, 0}, {width, height});
+ PremultipliedImage::copy(image, dstImage, {static_cast<uint32_t>(srcX), static_cast<uint32_t>(srcY)}, {0, 0}, size);
try {
return std::make_unique<style::Image>(
diff --git a/src/mbgl/sprite/sprite_parser.hpp b/src/mbgl/sprite/sprite_parser.hpp
index 7d545a6d98..baba427f43 100644
--- a/src/mbgl/sprite/sprite_parser.hpp
+++ b/src/mbgl/sprite/sprite_parser.hpp
@@ -9,10 +9,10 @@ namespace mbgl {
// Extracts an individual image from a spritesheet from the given location.
std::unique_ptr<style::Image> createStyleImage(const std::string& id,
const PremultipliedImage&,
- uint32_t srcX,
- uint32_t srcY,
- uint32_t srcWidth,
- uint32_t srcHeight,
+ int32_t srcX,
+ int32_t srcY,
+ int32_t srcWidth,
+ int32_t srcHeight,
double ratio,
bool sdf,
style::ImageStretches&& stretchX = {},