]> granicus.if.org Git - postgresql/commitdiff
BLOBs containing NUL characters (ASCII 0) can be written to the
authorBruce Momjian <bruce@momjian.us>
Wed, 13 Oct 1999 02:26:37 +0000 (02:26 +0000)
committerBruce Momjian <bruce@momjian.us>
Wed, 13 Oct 1999 02:26:37 +0000 (02:26 +0000)
database, but they get truncated at the first NUL by lo_read
when they are read back. The reason for this is that lo_read in
Pg.xs is using the default:
    OUTPUT:
        RETVAL
        buf
which uses C's strlen() to work out the length of the scalar.

The code ought to read something more like:
    OUTPUT:
        RETVAL
        buf sv_setpvn((SV*)ST(2), buf, RETVAL);

I am not sure if this needs to be done on both lo_read methods
in this file, but I changed both and have not since had any
problems with truncated BLOBs.

Douglas Thomson <dougt@mugc.cc.monash.edu.au>

src/interfaces/perl5/Pg.xs

index 5419130a528f47be5496e9c138cf18122c36c33e..2c884c9c033ed5d5c1a84abc526d2d36327a3475 100644 (file)
@@ -1,6 +1,6 @@
 /*-------------------------------------------------------
  *
- * $Id: Pg.xs,v 1.12 1999/02/19 23:27:17 tgl Exp $
+ * $Id: Pg.xs,v 1.13 1999/10/13 02:26:37 momjian Exp $ with patch for NULs
  *
  * Copyright (c) 1997, 1998  Edmund Mergl
  *
@@ -643,7 +643,7 @@ lo_read(conn, fd, buf, len)
                }
        OUTPUT:
                RETVAL
-               buf
+               buf sv_setpvn((SV*)ST(2), buf, RETVAL);   /* to handle NULs */
 
 int
 lo_write(conn, fd, buf, len)
@@ -1029,7 +1029,7 @@ lo_read(conn, fd, buf, len)
                }
        OUTPUT:
                RETVAL
-               buf
+               buf sv_setpvn((SV*)ST(2), buf, RETVAL);   /* to handle NULs */
 
 
 int