php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79311 enchant_dict_suggest() fails on big endian architecture
Submitted: 2020-02-27 10:50 UTC Modified: 2020-02-28 12:32 UTC
From: vibhutisawant18 at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Enchant related
PHP Version: PHP 7.3 OS: Ubuntu 16.04
Private report: No CVE-ID: None
 [2020-02-27 10:50 UTC] vibhutisawant18 at gmail dot com
Description:
------------
ext/enchant/tests/dict_suggest.phpt TC fails as enchant_dict_suggest function is not compatible on Big Endian architecture.
The failure is observed at memcpy function in ext/enchant/enchant.c. 
enchant_dict_suggest function fails to return an array of suggestions, instead it returns null object.

It can be observed that the n_sugg variable is of type int(4 bytes) whereas the n_sugg_st variable is of type size_t(8 bytes).
Hence due to different memory alignment on big endian system, the memcpy fails to copy the memory blocks containing actual data.

AS a workaround, I found that by declaring data type of n_sugg as size_t instead of int, the TC passed on both, Little and Big endian system.Kindly let me know if I shall raise a PR with this changes.

PFB test result observed on Little and big endian architecture for respective TC(ext/enchant/tests/dict_suggest.phpt).

Little endian:

test@5dfe04cf73b3:~/php/php-src$ ./sapi/cli/php -f "ext/enchant/tests/dict_suggest.phpt"
--TEST--
enchant_dict_suggest() function
--CREDITS--
marcosptf - <marcosptf@yahoo.com.br>
--SKIPIF--
--FILE--
OK
OK
OK
--EXPECT--
OK
OK
OK

Big endian:

test@3e72af658118:~/php/php-src$ ./sapi/cli/php -f "ext/enchant/tests/dict_suggest.phpt"
--TEST--
enchant_dict_suggest() function
--CREDITS--
marcosptf - <marcosptf@yahoo.com.br>
--SKIPIF--
--FILE--
OK
OK
dict suggest failed
--EXPECT--
OK
OK
OK





Patches

dict_suggest_patch.patch (last revision 2020-02-28 04:24 UTC by vibhutisawant18 at gmail dot com)

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-02-27 11:06 UTC] cmb@php.net
Using memcpy() to assign a `size_t` value to an `int` variable is
… interesting.  I'd *start* by changing this to proper
assignments.
 [2020-02-27 11:06 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2020-02-27 11:20 UTC] daverandom@php.net
-Package: Variables related +Package: Enchant related
 [2020-02-28 04:24 UTC] vibhutisawant18 at gmail dot com
The following patch has been added/updated:

Patch Name: dict_suggest_patch.patch
Revision:   1582863865
URL:        https://bugs.php.net/patch-display.php?bug=79311&patch=dict_suggest_patch.patch&revision=1582863865
 [2020-02-28 12:31 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #79311: enchant_dict_suggest() fails on big endian architecture
On GitHub:  https://github.com/php/php-src/pull/5222
Patch:      https://github.com/php/php-src/pull/5222.patch
 [2020-02-28 12:32 UTC] cmb@php.net
-Summary: enchant_dict_suggest() function fails on Big endian architecture +Summary: enchant_dict_suggest() fails on big endian architecture -PHP Version: master-Git-2020-02-27 (Git) +PHP Version: PHP 7.3 -Assigned To: +Assigned To: cmb
 [2020-02-28 12:32 UTC] cmb@php.net
Thanks for the patch!  I would prefer to clean that up right away;
could you please check PR #5222 (see link above)?
 [2020-02-28 14:47 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=6adb885966502f53c69b9aeb0e2cbbeac3d6c65a
Log: Fix #79311: enchant_dict_suggest() fails on big endian architecture
 [2020-02-28 14:47 UTC] cmb@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC