If you have a sufficiently broken data page, pageinspect throws an
error when trying to examine the page:

ERROR:  invalid memory alloc request size 18446744073709551451

This is pretty unhelpful; it would be better not to try to print the
data instead of dying.  With that, at least you can know where the
problem is.

This was introduced in d6061f83a166 (2015).  Proposed patch to fix it
(by having the code print a null "data" instead of dying) is attached.

-- 
Álvaro Herrera
diff --git a/contrib/pageinspect/heapfuncs.c b/contrib/pageinspect/heapfuncs.c
index 64a6e351d5..909fdee406 100644
--- a/contrib/pageinspect/heapfuncs.c
+++ b/contrib/pageinspect/heapfuncs.c
@@ -228,11 +228,17 @@ heap_page_items(PG_FUNCTION_ARGS)
 
 			/* Copy raw tuple data into bytea attribute */
 			tuple_data_len = lp_len - tuphdr->t_hoff;
-			tuple_data_bytea = (bytea *) palloc(tuple_data_len + VARHDRSZ);
-			SET_VARSIZE(tuple_data_bytea, tuple_data_len + VARHDRSZ);
-			memcpy(VARDATA(tuple_data_bytea), (char *) tuphdr + tuphdr->t_hoff,
-				   tuple_data_len);
-			values[13] = PointerGetDatum(tuple_data_bytea);
+			if (tuple_data_len < BLCKSZ)
+			{
+				tuple_data_bytea = (bytea *) palloc(tuple_data_len + VARHDRSZ);
+				SET_VARSIZE(tuple_data_bytea, tuple_data_len + VARHDRSZ);
+				memcpy(VARDATA(tuple_data_bytea), (char *) tuphdr + tuphdr->t_hoff,
+					   tuple_data_len);
+				values[13] = PointerGetDatum(tuple_data_bytea);
+				nulls[13] = false;
+			}
+			else
+				nulls[13] = true;
 
 			/*
 			 * We already checked that the item is completely within the raw

Reply via email to