Subject: Re: Bug in copy binary of variable length fields

From: postarch (Postgres Mailing Archive)
Date: Thu, 30 Jul 92 16:27:09 PDT

you write:
> Description: 
> "copy binary" would crash if any of the attributes had a varlena stucture 
> ( eg text ). 
>  
> Source Files Changed: ~postgres/src/commands/copy.c 
>  
> Procedure Changed : CopyFrom() 
>  
>         line number : 378 
>         was         : values[i] = (Datum) (ptr + 4); 
>         now         : values[i] = (Datum) ptr; 
>          
>         line number : 379
>         was         : LONGALIGN(ptr + * (unsigned long *) ptr + 4);
>         now         : LONGALIGN(ptr + * (unsigned long *) ptr); 
>          
> Explanation: 
>         The varlena type is 
>         /* ---------------- 
>          *      struct varlena 
>          * ---------------- 
>          */ 
>          struct varlena { 
>                 long    vl_len;
>                 char    vl_dat[1]; 
>            };
>         the original source was skipping over the vl_len field.  
>         When the code for copy was expecting to find the vl_len is was
>         instead finding the fist four bytes of the vl_dat field. 

You have it exactly right.  This bug depended on another bug that was
fixed not too long ago.  We used to write the length of varlenas to disk
twice.  Thus skipping 4 bytes wouldn't have caused any problems.  When
we stopped the duplication we didn't test everything very thoroughly.
Thanks for the diffs.

Jeff Meredith
[email-masked]