Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed bug #62070

Collator::getSortKey() was returning an unterminated string
due the length given to RETURN_STRINGL being off by one.
  • Loading branch information...
commit 51286bd8e5a7acd75326fae497313725e4acf234 1 parent 5d61e56
@cataphract cataphract authored
Showing with 19 additions and 1 deletion.
  1. +3 −1 ext/intl/collator/collator_sort.c
  2. +16 −0 ext/intl/tests/bug62070.phpt
View
4 ext/intl/collator/collator_sort.c
@@ -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 );
@@ -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);
}
/* }}} */
View
16 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
@smalyshev Owner

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Please sign in to comment.
Something went wrong with that request. Please try again.