PR# 19436 Infinite loop in routine {UTF_CONVERTER}.is_valid_utf_16
Problem Report Summary
Submitter: finnianr
Category: EiffelBase
Priority: High
Date: 2018/04/07
Class: Bug
Severity: Critical
Number: 19436
Release: 16.05
Confidential: No
Status: Closed
Responsible:
Environment: linux
Synopsis: Infinite loop in routine {UTF_CONVERTER}.is_valid_utf_16
Description
if argument `s' for `is_valid_utf_16' consists of a single code with value < 0xD800 then the for loop will never terminate. I checked the lastest github version and it hasn't been fixed.
To Reproduce
Problem Report Interactions
Fixed in rev#101649 of EiffelStudio 18.05 intermediate release. As a temporary solution you can copy the following implementation of the feature and recompile the all the precompiles and projects from scratch: is_valid_utf_16 (s: SPECIAL [NATURAL_16]): BOOLEAN -- Is `s' a valid UTF-16 Unicode sequence? local i, n: INTEGER c: NATURAL_16 do from i := 0 n := s.count Result := True until i >= n or not Result loop c := s.item (i) if c < 0xD800 or c >= 0xE000 then -- Codepoint from Basic Multilingual Plane: one 16-bit code unit, this is valid Unicode. elseif c <= 0xDBFF then i := i + 1 if i < n then c := s.item (i) Result := 0xDC00 <= c and c <= 0xDFF else -- Surrogate pair is incomplete, clearly not a valid UTF-16 sequence. Result := False end else -- Invalid starting surrogate pair which should be between 0xD800 and 0xDBFF. Result := False end i := i + 1 .... Output truncated, Click download to get the full message
Added an example test#utf003.
Also the loop termination condition is wrong: until i > n or not Result It should be until i >= n or not Result since s [n] is out of bounds