Closed Bug 141866 Opened 22 years ago Closed 22 years ago

NS_ConvertUTF8toUCS2(ptr, length) doesn't correctly handle given length

Categories

(Core :: XPCOM, defect)

defect
Not set
major

Tracking

()

RESOLVED FIXED

People

(Reporter: mikepinkerton, Assigned: jag+mozilla)

References

Details

(Keywords: topembed+)

Attachments

(1 file)

in trying to use
      NS_ConvertUTF8toUCS2( const char* aCString, PRUint32 aLength )
        {
          Init( nsDependentCString( aCString, aLength ) );
        }

I discovered that even if aCString is null terminated, nsDependentCString will
assert in Rebind if the null comes after |aLength| bytes. 

this blocks work in 69566
topembed because it blocks a topembed bug
Blocks: 69566
Keywords: mozilla1.0, topembed
No longer blocks: 69566
The problem isn't with nsDependentCString, that does exactly what it should.
The problem is that we didn't allow a substring of the |const char*| to be
passed in.
Comment on attachment 82131 [details] [diff] [review]
Make NS_ConvertUTF8toUCS2(ptr, length) work with substrings

sr=scc, and thanks for the fix, jag
Attachment #82131 - Flags: superreview+
Updating summary.
Summary: nsDependentCString doesn't correctly handle given length when looking for null termination → NS_ConvertUTF8toUCS2(ptr, length) doesn't correctly handle given length
this really does block 69566
Blocks: 69566
Comment on attachment 82131 [details] [diff] [review]
Make NS_ConvertUTF8toUCS2(ptr, length) work with substrings

r=pink.

i'm going to land this.
Attachment #82131 - Flags: review+
landed on trunk. we need this on the branch for 69566
Keywords: topembedadt1.0.0, topembed+
actually, this patch doesn't work.
removing adt keyword. it appears we were premature. the patch doesn't work.
also, don't a whole bunch of other things that use nsDependent*String(foo, len)
have to be changed as well?
Keywords: adt1.0.0
Other things that use nsDependent[C]String(str,len) should already have been
fixed.  The patch certainly should fix the assertion, and seems like the right
thing to do.  What doesn't work about it?  (nsDependentCString is an
nsAFlatCString, which implies that the buffer is null-terminated at its length.
 |Substring| returns an object that is an nsASingleFragmentCString (one higher
in the hierarchy), which doesn't imply null-termination.)
(That is, they should have been fixed if the |len| that they were providing was
there to indicate that a substring was desired rather than that the length of
the string was already known.)
i'm still getting the assert about it having to be null terminated, even with
the change, but then again the dependency checking in the win32 gmake build is
so bad, it might be a phantom. i'm doing a full rebuild now just to be certain.
did a full rebuild, it still asserts, but now with a different assert.

if i don't give it a length, it's ok. if i do give it a length, it asserts now
that this can only be used with a known UTF8 string (which it is). What's the
difference?
What's the stack for the new assertion?  And what's the input string?
Hmmm... That sounds like your buffer contains a character it can't decode.
If you don't give NS_ConvertUTF8toUCS2 a length, it'll go find the zero
terminator and determine the length of the buffer that way. It's the equivalent
of doing |NS_ConvertUTF8toUCS2(str, strlen(str))|.

So, since it can decode the utf8 buffer just fine if you don't give it a length,
it sounds like you're cutting some utf8 char in half (or whatever) with the
length you've given.
hrm, this is just a simple ascii string, all characters are in the range 00 ->
7F. i dont see any multi-byte characters anywhere in my string.
So what's the stack for the new assertion?  We're only guessing at which
assertion you might have hit.
landed. we need this on the branch for embedding (for 69566)
Keywords: adt1.0.0
adding adt1.0.0+.  Please get drivers approval before checking into the 1.0 branch.
Keywords: adt1.0.0adt1.0.0+
Comment on attachment 82131 [details] [diff] [review]
Make NS_ConvertUTF8toUCS2(ptr, length) work with substrings

a=rjesup@wgate.com (make sure it's in trunk too)
Attachment #82131 - Flags: approval+
landed on 1.0.0 branch on 5/16/02
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Keywords: adt1.0.0+fixed1.0.0
Component: String → XPCOM
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: