From 972f810767d18385e4043dcd03eeb4618ccfcc19 Mon Sep 17 00:00:00 2001 From: Geoff Lang Date: Fri, 14 Jul 2023 12:05:40 -0400 Subject: [PATCH] Reject program binaries when the renderer string changes If the underlying driver changes, reject program binaries from the old versions. The driver is supposed to do this for us (on OpenGL, at least) but this adds some extra protection. Bug: angleproject:4981 Change-Id: Id9486d8e6f9136970c0d7c37d59dea5d43b0a50e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4685317 Reviewed-by: Shahbaz Youssefi Commit-Queue: Geoff Lang --- src/common/BinaryStream.h | 7 +++++++ src/libANGLE/Context.h | 1 + src/libANGLE/Program.cpp | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/src/common/BinaryStream.h b/src/common/BinaryStream.h index 1ef734bef..2796827bd 100644 --- a/src/common/BinaryStream.h +++ b/src/common/BinaryStream.h @@ -249,6 +249,13 @@ class BinaryOutputStream : angle::NonCopyable write(v.c_str(), v.length()); } + void writeString(const char *v) + { + size_t len = strlen(v); + writeInt(len); + write(v, len); + } + void writeBytes(const unsigned char *bytes, size_t count) { write(bytes, count); } void writeBool(bool value) diff --git a/src/libANGLE/Context.h b/src/libANGLE/Context.h index 28820a418..55736e522 100644 --- a/src/libANGLE/Context.h +++ b/src/libANGLE/Context.h @@ -670,6 +670,7 @@ class Context final : public egl::LabeledObject, angle::NonCopyable, public angl bool isWebGL() const { return mState.isWebGL(); } bool isWebGL1() const { return mState.isWebGL1(); } + const char *getRendererString() const { return mRendererString; } bool isValidBufferBinding(BufferBinding binding) const { return mValidBufferBindings[binding]; } diff --git a/src/libANGLE/Program.cpp b/src/libANGLE/Program.cpp index 7cf6e6506..65e9c5205 100644 --- a/src/libANGLE/Program.cpp +++ b/src/libANGLE/Program.cpp @@ -3522,6 +3522,8 @@ angle::Result Program::serialize(const Context *context, angle::MemoryBuffer *bi stream.writeInt(angle::GetANGLESHVersion()); + stream.writeString(context->getRendererString()); + // nullptr context is supported when computing binary length. if (context) { @@ -3632,6 +3634,13 @@ angle::Result Program::deserialize(const Context *context, return angle::Result::Stop; } + std::string rendererString = stream.readString(); + if (rendererString != context->getRendererString()) + { + infoLog << "Cannot load program binary due to changed renderer string."; + return angle::Result::Stop; + } + int majorVersion = stream.readInt(); int minorVersion = stream.readInt(); if (majorVersion != context->getClientMajorVersion() ||