Skip to content

Commit

Permalink
Fixed bug #62070
Browse files Browse the repository at this point in the history
Collator::getSortKey() was returning an unterminated string
due the length given to RETURN_STRINGL being off by one.
  • Loading branch information
cataphract committed May 23, 2012
1 parent 5d61e56 commit 51286bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ext/intl/collator/collator_sort.c
Expand Up @@ -594,6 +594,8 @@ PHP_FUNCTION( collator_get_sort_key )
RETURN_FALSE;
}

/* ucol_getSortKey is exception in that the key length includes the
* NUL terminator*/
key_len = ucol_getSortKey(co->ucoll, ustr, ustr_len, key, 0);
if(!key_len) {
efree( ustr );
Expand All @@ -605,7 +607,7 @@ PHP_FUNCTION( collator_get_sort_key )
if(!key_len) {
RETURN_FALSE;
}
RETURN_STRINGL((char *)key, key_len, 0);
RETURN_STRINGL((char *)key, key_len - 1, 0);
}
/* }}} */

Expand Down
16 changes: 16 additions & 0 deletions ext/intl/tests/bug62070.phpt
@@ -0,0 +1,16 @@
--TEST--
Bug #62070: Collator::getSortKey() returns garbage
--SKIPIF--
<?php
if (!extension_loaded('intl'))
die('skip intl extension not enabled');
--FILE--
<?php
$s1 = 'Hello';

$coll = collator_create('en_US');
$res = collator_get_sort_key($coll, $s1);

echo urlencode($res);
--EXPECT--
5%2F%3D%3DC%01%09%01%8F%08

This comment has been minimized.

Copy link
@smalyshev

smalyshev Jul 30, 2012

Contributor

I think we have to stop putting collation keys into tests, they are not stable between ICU versions and this test fails for me on ICU 4.2.1.

This comment has been minimized.

Copy link
@cataphract

cataphract Jul 30, 2012

Author Contributor

I can confirm it also fails on ICU 4.4, but passes on 49. I'll limit the test to ICU 49 for now. If it fails again in the future, we'll have to reconsider this approach.

0 comments on commit 51286bd

Please sign in to comment.