Validate SkDescriptor length alignment on read When deserializing an SkDescriptor in MakeFromBuffer, we must validate that the length is a multiple of 4 (SkIsAlign4). Otherwise, passing an unaligned length to SkAutoDescriptor triggers an assertion failure/abort inside SkDescriptor::Alloc. Bug: b/524792615 Test: skia_unittests --gtest_filter="Descriptor*" Change-Id: Id3db0fb85c8baa50db617ff93bf34f1d6be0a471 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1287596 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Tzarial <zork@google.com>
diff --git a/src/core/SkDescriptor.cpp b/src/core/SkDescriptor.cpp index 7ee966d..941a0d3 100644 --- a/src/core/SkDescriptor.cpp +++ b/src/core/SkDescriptor.cpp
@@ -178,8 +178,11 @@ if (!buffer.readPad32(&descriptorHeader, sizeof(SkDescriptor))) { return {}; } // Basic bounds check on header length to make sure that bodyLength calculation does not - // underflow. - if (descriptorHeader.getLength() < sizeof(SkDescriptor)) { return {}; } + // underflow. Also ensure alignment. + if (descriptorHeader.getLength() < sizeof(SkDescriptor) || + !SkIsAlign4(descriptorHeader.getLength())) { + return {}; + } uint32_t bodyLength = descriptorHeader.getLength() - sizeof(SkDescriptor); // Make sure the fLength makes sense with respect to the incoming data.