php-src/ext/mbstring/libmbfl
NathanFreeman fa0401b0b5 Fix GH-9535 (unintended behavior change for mb_strcut in PHP 8.1)
The existing implementation of mb_strcut extracts part of a
multi-byte encoded string by pulling out raw bytes and then running
them through a conversion filter to ensure that the output is valid
in the requested encoding.

If the conversion filter emits error markers when doing the final
'flush' operation which ends the conversion of the extracted bytes,
these error markers may (in some cases) be included in the output.
The conversion operation does not respect the value of
mb_substitute_character; rather, it always uses '?' as an error marker.
So this issue manifests itself as unwanted '?' characters being
inserted into the output.

This issue has existed for a long time, but became noticeable in PHP
8.1 because for at least some of the supported text encodings, mbstring
is now more strict about emitting error markers when strings end in an
illegal state.

The simplest fix is to suppress error markers during the final flush
operation.

While working on a fix for this problem, another problem with mb_strcut
was discovered; since it decides when to stop consuming bytes from
the input by looking at the byte length of its OUTPUT, anything which
causes extra bytes to be emitted to the output may cause mb_strcut to
not consume all the bytes in the requested range.

The one case where we DO emit extra output bytes is for encodings
which have a selectable mode, like ISO-2022-JP; if a string in such
an encoding ends in a mode which is not the default, we emit an ending
escape sequence which changes back to the default mode. This is done
so that concatenating strings in such encodings is safe.

However, as mentioned, this can cause the output of mb_strcut to be
shorter than it logically should be. This bug has existed for a long
time, and fixing it now will be a BC break, so we may not fix it right
away.

Therefore, tests for THIS fix which don't pass because of that OTHER
bug have been split out into a separate test file (gh9535b.phpt), and
that file has been marked XFAIL.
2022-11-13 14:37:55 +02:00
..
filters In legacy text conversion filters, reset filter state in 'flush' function 2022-10-10 20:46:12 +09:00
mbfl Fix GH-9535 (unintended behavior change for mb_strcut in PHP 8.1) 2022-11-13 14:37:55 +02:00
nls Remove redundant includes from mbstring (and make sure correct config.h is used) 2020-08-31 23:17:58 +02:00
config.h.w32 Remove unused symbol definition 2019-05-11 19:47:54 +02:00
LICENSE Integrate libmbfl docs to README.md and LICENSE 2019-05-11 18:29:30 +02:00
README.md Integrate libmbfl docs to README.md and LICENSE 2019-05-11 18:29:30 +02:00

libmbfl

This is libmbfl, a streamable multibyte character code filter and converter library, written by Shigeru Kanemoto.

The original version of libmbfl is developed and distributed at https://github.com/moriyoshi/libmbfl under the LGPL 2.1 license. See the LICENSE file for licensing information.

The libmbfl library is bundled with PHP as a fork of the original repository and is not in sync with the upstream. As such, the libmbfl directory is directly modified in the php-src repository.

Changelog

October 2017

  • Since 2017, it is forked and bundled in the php-src repository. For the list of changes related to PHP see the PHP NEWS change logs.

Version 1.3.2 August 20, 2011

  • Added JISX-0213:2004 based encoding : Shift_JIS-2004, EUC-JP-2004, ISO-2022-JP-2004 (rui).
  • Added gb18030 encoding (rui).
  • Added CP950 with user user defined area based on Big5 (rui).
  • Added mapping for user defined character area to CP936 (rui).
  • Added UTF-8-Mobile to support the pictogram characters defined by mobile phone carrier in Japan (rui).

Version 1.3.1 August 5, 2011

  • Added check for invalid/obsolete utf-8 encoding (rui).

Version 1.3.0 August 1, 2011

  • Added encoding conversion between Shift_JIS and Unicode (6.0 or PUA) for pictogram characters defined by mobile phone carrier in Japan (rui).

    Detailed info

  • Fixed encoding conversion of cp5022x for user defined area (rui).

  • Added MacJapanese (SJIS-mac) for legacy encoding support (rui).

  • Backport from PHP 5.2 (rui).

Version 1.1.0 March 02, 2010

  • Added cp5022x encoding (moriyoshi)
  • Added ISO-2022-JP-MS (moriyoshi)
  • Moved to github.com from sourceforge.jp (moriyoshi)

Earlier versions

  • 1998/11/10 sgk implementation in C++
  • Rewriting with sgk C 1999/4/25.
  • 1999/4/26 Implemented sgk input filter. Add filter while estimating kanji code.
  • 1999/6 Unicode support.
  • 1999/6/22 Changed sgk license to LGPL.

Credits

Marcus Boerger helly@php.net Hayk Chamyan hamshen@gmail.com Wez Furlong wez@thebrainroom.com Rui Hirokawa hirokawa@php.net Shigeru Kanemoto sgk@happysize.co.jp U. Kenkichi kenkichi@axes.co.jp Moriyoshi Koizumi moriyoshi@php.net Hironori Sato satoh@jpnnet.com Tsukada Takuya tsukada@fminn.nagano.nagano.jp Tateyama tateyan@amy.hi-ho.ne.jp Den V. Tsopa tdv@edisoft.ru Maksym Veremeyenko verem@m1stereo.tv Haluk AKIN halukakin@gmail.com