diff --git a/generator/templates/dawn_wire/WireCmd.cpp b/generator/templates/dawn_wire/WireCmd.cpp index 60640f7c68..8199888cbb 100644 --- a/generator/templates/dawn_wire/WireCmd.cpp +++ b/generator/templates/dawn_wire/WireCmd.cpp @@ -687,16 +687,20 @@ namespace dawn_wire { } bool DeserializeWGPUDeviceProperties(WGPUDeviceProperties* deviceProperties, - const volatile char* deserializeBuffer) { - size_t devicePropertiesSize = SerializedWGPUDevicePropertiesSize(deviceProperties); + const volatile char* deserializeBuffer, + size_t deserializeBufferSize) { + if (deserializeBufferSize == 0) { + // TODO(enga): Remove this after updating Chromium. + deserializeBufferSize = SerializedWGPUDevicePropertiesSize(deviceProperties); + } const volatile WGPUDevicePropertiesTransfer* transfer = nullptr; - if (GetPtrFromBuffer(&deserializeBuffer, &devicePropertiesSize, 1, &transfer) != + if (GetPtrFromBuffer(&deserializeBuffer, &deserializeBufferSize, 1, &transfer) != DeserializeResult::Success) { return false; } return WGPUDevicePropertiesDeserialize(deviceProperties, transfer, &deserializeBuffer, - &devicePropertiesSize, + &deserializeBufferSize, nullptr) == DeserializeResult::Success; } diff --git a/src/include/dawn_wire/Wire.h b/src/include/dawn_wire/Wire.h index 5d5d1bebda..805fefffc2 100644 --- a/src/include/dawn_wire/Wire.h +++ b/src/include/dawn_wire/Wire.h @@ -49,8 +49,10 @@ namespace dawn_wire { const WGPUDeviceProperties* deviceProperties, char* serializeBuffer); + // TODO(enga): Remove the default value after updating Chromium. DAWN_WIRE_EXPORT bool DeserializeWGPUDeviceProperties(WGPUDeviceProperties* deviceProperties, - const volatile char* deserializeBuffer); + const volatile char* deserializeBuffer, + size_t deserializeBufferSize = 0); } // namespace dawn_wire diff --git a/src/tests/unittests/wire/WireWGPUDevicePropertiesTests.cpp b/src/tests/unittests/wire/WireWGPUDevicePropertiesTests.cpp index 120e4a9aba..3d97e105c1 100644 --- a/src/tests/unittests/wire/WireWGPUDevicePropertiesTests.cpp +++ b/src/tests/unittests/wire/WireWGPUDevicePropertiesTests.cpp @@ -34,8 +34,24 @@ TEST_F(WireWGPUDevicePropertiesTests, SerializeWGPUDeviceProperties) { dawn_wire::SerializeWGPUDeviceProperties(&sentWGPUDeviceProperties, buffer.data()); WGPUDeviceProperties receivedWGPUDeviceProperties; - dawn_wire::DeserializeWGPUDeviceProperties(&receivedWGPUDeviceProperties, buffer.data()); + ASSERT_TRUE(dawn_wire::DeserializeWGPUDeviceProperties(&receivedWGPUDeviceProperties, + buffer.data(), buffer.size())); ASSERT_TRUE(receivedWGPUDeviceProperties.textureCompressionBC); ASSERT_FALSE(receivedWGPUDeviceProperties.pipelineStatisticsQuery); ASSERT_TRUE(receivedWGPUDeviceProperties.timestampQuery); } + +// Test that deserialization if the buffer is just one byte too small fails. +TEST_F(WireWGPUDevicePropertiesTests, DeserializeBufferTooSmall) { + WGPUDeviceProperties sentWGPUDeviceProperties = {}; + + size_t sentWGPUDevicePropertiesSize = + dawn_wire::SerializedWGPUDevicePropertiesSize(&sentWGPUDeviceProperties); + std::vector buffer; + buffer.resize(sentWGPUDevicePropertiesSize); + dawn_wire::SerializeWGPUDeviceProperties(&sentWGPUDeviceProperties, buffer.data()); + + WGPUDeviceProperties receivedWGPUDeviceProperties; + ASSERT_FALSE(dawn_wire::DeserializeWGPUDeviceProperties(&receivedWGPUDeviceProperties, + buffer.data(), buffer.size() - 1)); +}