Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 38a2b95

Browse files
committed
Zero padding byte at end of GIN posting list.
This isn't strictly necessary, but helps debugging.
1 parent f235db0 commit 38a2b95

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/backend/access/gin/ginpostinglist.c

+13
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ decode_varbyte(unsigned char **ptr)
176176
* 'maxsize' bytes in size. The number items in the returned segment is
177177
* returned in *nwritten. If it's not equal to nipd, not all the items fit
178178
* in 'maxsize', and only the first *nwritten were encoded.
179+
*
180+
* The allocated size of the returned struct is short-aligned, and the padding
181+
* byte at the end, if any, is zero.
179182
*/
180183
GinPostingList *
181184
ginCompressPostingList(const ItemPointer ipd, int nipd, int maxsize,
@@ -188,9 +191,12 @@ ginCompressPostingList(const ItemPointer ipd, int nipd, int maxsize,
188191
unsigned char *ptr;
189192
unsigned char *endptr;
190193

194+
maxsize = SHORTALIGN_DOWN(maxsize);
195+
191196
result = palloc(maxsize);
192197

193198
maxbytes = maxsize - offsetof(GinPostingList, bytes);
199+
Assert(maxbytes > 0);
194200

195201
/* Store the first special item */
196202
result->first = ipd[0];
@@ -228,6 +234,13 @@ ginCompressPostingList(const ItemPointer ipd, int nipd, int maxsize,
228234
}
229235
result->nbytes = ptr - result->bytes;
230236

237+
/*
238+
* If we wrote an odd number of bytes, zero out the padding byte at the
239+
* end.
240+
*/
241+
if (result->nbytes != SHORTALIGN(result->nbytes))
242+
result->bytes[result->nbytes] = 0;
243+
231244
if (nwritten)
232245
*nwritten = totalpacked;
233246

0 commit comments

Comments
 (0)