From 5e760b9d63c12ef504a3fd3be75dd2511211165b Mon Sep 17 00:00:00 2001
From: Evdokimov Ilia <ilya.evdokimov@tantorlabs.com>
Date: Tue, 19 May 2026 17:17:01 +0300
Subject: [PATCH v1] Fix size check in statext_dependencies_deserialize()

The sanity check was using SizeOfItem(dependencies->ndeps) to validate
the bytea size, but SizeOfItem() expects the number of attributes in a
single dependency, not the number of dependencies. Replace it with
MinSizeOfItems(ndeps), which correctly computes the minimum expected
size as the header plus ndeps minimally-sized dependency items.
---
 src/backend/statistics/dependencies.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/backend/statistics/dependencies.c b/src/backend/statistics/dependencies.c
index e3a2f5817e0..95dcc218978 100644
--- a/src/backend/statistics/dependencies.c
+++ b/src/backend/statistics/dependencies.c
@@ -529,7 +529,7 @@ statext_dependencies_deserialize(bytea *data)
 		elog(ERROR, "invalid zero-length item array in MVDependencies");
 
 	/* what minimum bytea size do we expect for those parameters */
-	min_expected_size = SizeOfItem(dependencies->ndeps);
+	min_expected_size = MinSizeOfItems(dependencies->ndeps);
 
 	if (VARSIZE_ANY_EXHDR(data) < min_expected_size)
 		elog(ERROR, "invalid dependencies size %zu (expected at least %zu)",
-- 
2.34.1

