nickva commented on pull request #3488:
URL: https://github.com/apache/couchdb/pull/3488#issuecomment-812699068
It was interesting that we didn't hit this issue on CentOS 7 on 3.x so I was
curious and traced the `less` call when running that mango test:
```
10:9:04.429561 <0.11140.1> couch_ejson_compare:less_nif([{<<"ÿÿÿÿ">>}],
[{[{<<"forename">>,<<"Eddie">>}]}])
10:9:04.429783 <0.11140.1> couch_ejson_compare:less_nif/2 error badarg
10:9:04.429984 <0.11140.1> couch_ejson_compare:less_erl([{<<"ÿÿÿÿ">>}],
[{[{<<"forename">>,<<"Eddie">>}]}])
10:9:04.430254 <0.11140.1> couch_ejson_compare:less_list([{<<"ÿÿÿÿ">>}],
[{[{<<"forename">>,<<"Eddie">>}]}])
10:9:04.430506 <0.11140.1> couch_ejson_compare:less_erl({<<"ÿÿÿÿ">>},
{[{<<"forename">>,<<"Eddie">>}]})
10:9:04.430745 <0.11140.1> couch_ejson_compare:less_erl/2 --> 1
10:9:04.430903 <0.11140.1> couch_ejson_compare:less_list/2 --> 1
10:9:04.431088 <0.11140.1> couch_ejson_compare:less_erl/2 --> 1
```
Apparently in `3.x` we compare an object `{[{<<"forename">>,<<"Eddie">>}]}`
against a (highest?) marker, but that marker is not an object but a tuple with
one element `{<<"ÿÿÿÿ">>}`. `less_nif/2` then notices the object is not valid
ejson and throws a `badarg` error. The the code then falls back to Erlang
using `less_erl/2` and at least in this case return the correct result (highest
marker is greater than (`1`) than the object).
In `main` we compare against an actual object `{[{<<"ÿÿÿÿ">>, <<>>}]}` so
everything gets unpacked nicely then the old unicode library at least older
than 59 (and possible 53) didn't error out, but also didn't sort the
`<<255,255,255,255>>` as the highest element as intended. Here is centos 7 with
libicu-50.2-4.el7_7.x86_64, for example
```
couch_ejson_compare:less(<<"forename">>, <<255,255,255,255>>).
1
> couch_ejson_compare:less(<<"/">>, <<255,255,255,255>>).
-1
> couch_ejson_compare:less(<<"0">>, <<255,255,255,255>>).
1
```
and on mac os with icu4c 59:
```
> couch_ejson_compare:less(<<"forename">>, <<255,255,255,255>>).
-1
> couch_ejson_compare:less(<<"/">>, <<255,255,255,255>>).
-1
> couch_ejson_compare:less(<<"0">>, <<255,255,255,255>>).
-1
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]