henck / henck/rtf-html-php

WingDings font gives "iconv(): Detected an incomplete multibyte character in input string"

Open
#96 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
107
Forks
79
PR merge metrics
No merged PRs in 30d

Description

Reproduction

Convert file tekst2.zip using:

        $rtf = file_get_contents('tekst2.rtf');

        $document = new Document(rtrim($rtf, "\0"));  // remove ASCII 0, the NULL-byte.
        $formatter = new HtmlFormatter('UTF-8');
        $html = $formatter->Format($document);

This will throw an exception:

iconv(): Detected an incomplete multibyte character in input string at /.../public_html/vendor/henck/rtf-to-html/src/Html/HtmlFormatter.php:375
Analysis
  • On the first line "{\f1\fswiss\fcharset128 Wingdings;}" the WingDings font is defined with fcharset 128.
  • fcharset 128 is the Japanese Shift-JIS multibyte font. When the first character has a code of 128 or higher, the total character is compromised of two bytes.
  • HtmlFormatter.php is unware of the multibyte CP932 codepage. And calls DecodeUnicode() with only one character. iconv() then throws an exception, because only the half of the multibyte character was provided.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in HtmlFormatter.php around line 375 and trace DecodeUnicode() for characters from the fcharset 128 WingDings definition. Reproduce the conversion with tekst2.rtf, then verify that CP932 multibyte input no longer causes iconv() to report an incomplete character and that HTML conversion completes without the exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.