Skip to Content.
Sympa Menu

freetds - Re: PHP's mssql_fetch_row inserting '\0' on strings- ?

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Brian Bruns" <camber AT ais.org>
  • To: freetds AT franklin.oit.unc.edu
  • Subject: Re: PHP's mssql_fetch_row inserting '\0' on strings- ?
  • Date: Thu, 20 Jun 2002 16:27:14 -0400


> This message is in MIME format. Since your mail reader does not understand
> this format, some or all of this message may not be legible.
>
> ------_=_NextPart_000_01C21896.1F0C8370
> Content-Type: text/plain;
> charset="iso-8859-1"
>
> > From: Andre Costa [mailto:brblueser AT uol.com.br]
> > Sent: June 20, 2002 2:13 PM
>
> > Bingo! Nice shot =) Yes, resultant data with embedded \0s is twice the
> > size of the "right" data. So, this proves the assumptions
> > that UCS-2 vs.
> > ASCII is the source of the confusion, doesn't it? Maybe PHP
> > is allocating
> > a buffer for UCS-2 data and is indeed receiving ASCII?
> >
> > Looks like we're narrowing the probl down =)
>
> I think it's our problem. In fact, I think it's a libtds error.

> 2 The first work of the buffer pointed to by dbdata() is 0x6c6c6568
> ('lleh')? Isn't it odd the high bytes aren't zero? This is supposed to be
> a UCS-2 buffer!
>
> Hypothesis: When we return an unreconstructed UCS-2 buffer, we goof. We
> convert it to ASCII, and return that type, and don't set the length
> correctly. :(

Correct, tds_unicode2ascii is called in src/tds/read.c(tds_get_string), so
by the time it hits the row buffer it is an ascii (or whatever
client_charset is set to) string.

> What I'm seeing is consistent with what PHP would be getting from us, if PHP
> is not binding the nchar/nvarchar data to strings, but is taking our buffer
> verbatim. I don't know what they'd want to with UCS-2 encoded text, but
> that's another question. They might not be thinking about UCS-2 at all.
> They might see 47, think "ascii string, length 10" and go from there. I
> would.

Not exactly, PHP is allocating n = dbdatlen() size and then requesting
that we fill it with n characters, so we have n/2 valid characters and n/2
uninitialized garbage.

I think my patch in the other message will fix it but i don't have the
wherewithall to test it right now.



  • Re: PHP's mssql_fetch_row inserting '\0' on strings- ?, Brian Bruns, 06/20/2002

Archive powered by MHonArc 2.6.24.

Top of Page