Validate program binaries are the same CPU bit-ness.
ANGLE's program binary serialize/deserialize logic uses size_t and
other non-fixed sized integer types. This can cause crashes if the
CPU architecture changes between saving and loading of binaries.
Bug: chromium:1470074
Bug: angleproject:8223
Change-Id: Ib2529e0e6e66e28a184aa1ec94075e343e1f1d5e
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4752265
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
diff --git a/src/common/platform_helpers.cpp b/src/common/platform_helpers.cpp
index 2775bbe..dd232bf 100644
--- a/src/common/platform_helpers.cpp
+++ b/src/common/platform_helpers.cpp
@@ -162,4 +162,13 @@
return IsWindowsVersionOrLater(kVersionWindows11);
}
+bool Is64Bit()
+{
+#if defined(ANGLE_IS_64_BIT_CPU)
+ return true;
+#else
+ return false;
+#endif // defined(ANGLE_IS_64_BIT_CPU)
+}
+
} // namespace angle
diff --git a/src/common/platform_helpers.h b/src/common/platform_helpers.h
index 8535360..d078be1 100644
--- a/src/common/platform_helpers.h
+++ b/src/common/platform_helpers.h
@@ -126,6 +126,8 @@
bool IsWindows10OrLater();
bool IsWindows11OrLater();
+bool Is64Bit();
+
} // namespace angle
#endif // COMMON_PLATFORM_HELPERS_H_
diff --git a/src/libANGLE/Program.cpp b/src/libANGLE/Program.cpp
index b7fe4f6..61e825a 100644
--- a/src/libANGLE/Program.cpp
+++ b/src/libANGLE/Program.cpp
@@ -16,6 +16,7 @@
#include "common/bitset_utils.h"
#include "common/debug.h"
#include "common/platform.h"
+#include "common/platform_helpers.h"
#include "common/string_utils.h"
#include "common/utilities.h"
#include "compiler/translator/blocklayout.h"
@@ -3533,6 +3534,8 @@
reinterpret_cast<const unsigned char *>(angle::GetANGLEShaderProgramVersion()),
angle::GetANGLEShaderProgramVersionHashSize());
+ stream.writeBool(angle::Is64Bit());
+
stream.writeInt(angle::GetANGLESHVersion());
stream.writeString(context->getRendererString());
@@ -3640,6 +3643,13 @@
return angle::Result::Stop;
}
+ bool binaryIs64Bit = stream.readBool();
+ if (binaryIs64Bit != angle::Is64Bit())
+ {
+ infoLog << "cannot load program binaries across CPU architectures.";
+ return angle::Result::Stop;
+ }
+
int angleSHVersion = stream.readInt<int>();
if (angleSHVersion != angle::GetANGLESHVersion())
{
diff --git a/src/tests/test_utils/angle_test_instantiate.cpp b/src/tests/test_utils/angle_test_instantiate.cpp
index c6e7e30..535a1e0 100644
--- a/src/tests/test_utils/angle_test_instantiate.cpp
+++ b/src/tests/test_utils/angle_test_instantiate.cpp
@@ -362,15 +362,6 @@
IsPixel4XL();
}
-bool Is64Bit()
-{
-#if defined(ANGLE_IS_64_BIT_CPU)
- return true;
-#else
- return false;
-#endif // defined(ANGLE_IS_64_BIT_CPU)
-}
-
bool HasMesa()
{
#if defined(ANGLE_HAS_MESA)
diff --git a/src/tests/test_utils/angle_test_instantiate.h b/src/tests/test_utils/angle_test_instantiate.h
index 2314a86..ca7412d 100644
--- a/src/tests/test_utils/angle_test_instantiate.h
+++ b/src/tests/test_utils/angle_test_instantiate.h
@@ -48,7 +48,6 @@
bool IsSwiftshaderDevice();
bool IsIntelUHD630Mobile();
-bool Is64Bit();
bool HasMesa();
bool IsPlatformAvailable(const PlatformParameters ¶m);