mem2v1-analyze-overread.patch

text/plain

Filename: mem2v1-analyze-overread.patch
Type: text/plain
Part: 1
Message: memory-related bugs

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
src/backend/commands/analyze.c 0 0
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index bafdc80..2e0a869 100644
*** a/src/backend/commands/analyze.c
--- b/src/backend/commands/analyze.c
***************
*** 874,881 **** examine_attribute(Relation onerel, int attnum, Node *index_expr)
  	typtuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(stats->attrtypid));
  	if (!HeapTupleIsValid(typtuple))
  		elog(ERROR, "cache lookup failed for type %u", stats->attrtypid);
! 	stats->attrtype = (Form_pg_type) palloc(sizeof(FormData_pg_type));
! 	memcpy(stats->attrtype, GETSTRUCT(typtuple), sizeof(FormData_pg_type));
  	ReleaseSysCache(typtuple);
  	stats->anl_context = anl_context;
  	stats->tupattnum = attnum;
--- 874,881 ----
  	typtuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(stats->attrtypid));
  	if (!HeapTupleIsValid(typtuple))
  		elog(ERROR, "cache lookup failed for type %u", stats->attrtypid);
! 	stats->attrtype = (Form_pg_type) palloc(TYPE_FIXED_PART_SIZE);
! 	memcpy(stats->attrtype, GETSTRUCT(typtuple), TYPE_FIXED_PART_SIZE);
  	ReleaseSysCache(typtuple);
  	stats->anl_context = anl_context;
  	stats->tupattnum = attnum;
diff --git a/src/include/catalog/pg_tindex 9baed6c..3255897 100644
*** a/src/include/catalog/pg_type.h
--- b/src/include/catalog/pg_type.h
***************
*** 219,224 **** CATALOG(pg_type,1247) BKI_BOOTSTRAP BKI_ROWTYPE_OID(71) BKI_SCHEMA_MACRO
--- 219,228 ----
  
  } FormData_pg_type;
  
+ /* Size of fixed part of pg_type tuples, not counting var-length fields. */
+ #define TYPE_FIXED_PART_SIZE \
+ 	 (offsetof(FormData_pg_type,typcollation) + sizeof(Oid))
+ 
  /* ----------------
   *		Form_pg_type corresponds to a pointer to a row with
   *		the format of pg_type relation.