[SOLVED] Illegal character encoding in GalleryPhpVm.class

Raybdbomb2

Joined: 2005-05-18
Posts: 14
Posted: Wed, 2005-05-18 18:02

I just installed G2 B3 from scratch, and I get this message on the main page:
Date:
Warning: mb_convert_encoding(): Illegal character encoding specified in /home/rdehler/raybdbomb.com/photos/modules/core/classes/GalleryPhpVm.class on line 70
05/18/2005
Size: 0 items
Owner: Gallery Administrator
It's located at http://raybdbomb.com/photos

----

Gallery URL (optional):http://raybdbomb.com/photos
Gallery version:G2B3
Webserver (with version):Apache 2.0.54
Datatabase (with version):Mysql 4.1.11
PHP version (eg 4.2.1):4.3.11
phpinfo URL (optional):
Graphics Toolkit(s):GD, NetPBM
Operating system:FreeBSD 5.4
Web browser/version:Mozilla/IE/Doesn'tMatter
G1 version (for migration bugs):n/a

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-05-18 23:12

Raybdbomb2, thanks for reporting that.
Could you edit the file /home/rdehler/raybdbomb.com/photos/modules/core/classes/GalleryPhpVm.class with a (text) editor?
Before line 70 (just before return mb_convert_encoding($string, $outCharset, $inCharset);), could you add this:

global $gallery;
$gallery->debug('mb_convert_encoding(' . $string . ', ' . $outCharset . ', ' . $inCharset . ');');

then save the file with this change.
and activate 'buffered' debug mode in config.php (open config.php in an editor and find the line to change the debug mode).

then, browse around in g2 to cause this warning.
in the debug output, search for the string "mb_convert_encoding" and post the complete string mb_convert_encoding(..., ... , ...); to the forums.

then perhaps we can find the problem. :)

i just tested what i've described it, but i didn't get any mb_convert debug output. not sure what causes main.php to use this function, at least you should get some debug output...

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Wed, 2005-05-18 23:13

I don't see any warning on that page.. is it resolved? If not, does it appear only when logged in? What language have you selected?

 
USFeric

Joined: 2005-04-19
Posts: 3
Posted: Thu, 2005-05-19 12:26

This is on Solaris 9/PHP 4.3.10, So YMMV.

The problem is with nl_langinfo(). It was returning '646' as the locale, which mb_convert_encoding() doesn't understand as a valid codeset. This didn't make any sense because my locale should be ASCII, but then I found out the ISO_646 is an alias for the ASCII codeset. As a workaround, I changed the nl_langinfo() function in modules/core/classes/GalleryPhpVm.class to:

function nl_langinfo($item) {
if (nl_langinfo($item) == '646') {
return "ASCII";
} else {
return nl_langinfo($item);
}
}

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-05-19 14:25

USFeric, thank you, this is very useful debug information. the question is now if '646' is a valid abbreviation for 'ISO_646' or if solaris or your solaris does return something invalid.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2005-05-19 15:53

USFeric, search for "Remap some known charset issues" in modules/core/classes/helpers/GalleryCharsetHelper_simple.class
Let us know if putting a case '646' here does the trick.. if so we can add that to cvs.

 
USFeric

Joined: 2005-04-19
Posts: 3
Posted: Thu, 2005-05-19 17:30

mindless,

that 'switch' statement is inside the 'else' block which begins on line 55, so it never gets run if the nl_langinfo() function exists. When I take the 'switch' statement out of the 'else' block (closing the 'else' block on line 76 instead of 93), and add a case for 646, it works. Hope that makes sense.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2005-05-19 18:34

it makes sense to map unusual nl_langinfo output too.. but let's add a separate "switch" inside that part of the if block; can you post your patch? thanks!

 
Raybdbomb2

Joined: 2005-05-18
Posts: 14
Posted: Thu, 2005-05-19 23:51

valiant

thanks for the response.

I did as you said, and there was no reference to mb_convert_encoding in the debugging output.

I "fixed" it by just having the function return $string instead of the passthrough function.

It probably lost some functionality (that I don't use anyway most likely), but it's better than seeing an error.

 
rickupusa

Joined: 2005-03-15
Posts: 2
Posted: Fri, 2005-05-20 00:33

Hi all,

I just upgraded from B2 to B3 and the "Warning: mb_convert_encoding(): Illegal character encoding specified in /path/to/GalleryPhpVm.class on line 70" the only issue I had (I think).

So I followed valiant's advice to Raybdbomb2 and I was also unable to locate any reference to mb_convert_encoding.

I have been trying the other advice mentioned in the thread but so far I haven't gotten rid of the message.

This is running on 4.9-STABLE FreeBSD and PHP Version 4.3.x

Thanks for reading and please advise.

Rick

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2005-05-20 00:55

rickupusa, can you post what you changed?
did you successfully turn on debug output? (there will be lots of output)

 
rickupusa

Joined: 2005-03-15
Posts: 2
Posted: Fri, 2005-05-20 19:30

mindless,

Thanks for the reply.

I snagged http://raybdbomb.com/photos/modules/core/classes/GalleryPhpVm.class

and it is working so far so good.

I did successfully turn on buffered output but at this point I am happy and everyone seems to be aware that Solaris and FreeBSD seem to have this problem but I can provide more info if you want.

In fact, I have several FreeBSD 4.x with PHP 4.x and FreeBDSD 5.x with php5 servers I can test with so feel free to let me know if you want me to try anything else.

May I ask what OS Gallery2 developers generall use and test on?

Thanks again,

Rick

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2005-05-20 22:18

rickupusa, and anyone who sees this warning.. we'd much rather have you debug and find out what string your nl_langinfo or setlocale is returning so we can add a mapping in GalleryCharsetHelper_simple.. this will help out other people too!
Edit modules/core/classes/helpers/GalleryCharsetHelper_simple.class and add print or $gallery->debug statements to find out what $sourceEncoding it is getting.

FYI, I'm on freebsd 4.11 and don't have any warnings.

 
RobFerrer

Joined: 2005-03-10
Posts: 33
Posted: Mon, 2005-05-30 10:20

Hi,

I'm having this problem with a fresh install of G2B3, running on Apache 1.3.33/FreeBSD 5.3/PHP 4.3.11.

See http://yuccgallery.fclusers.co.uk/ (buffered debugging on)

If you need any mor information please let me know

Thanks

Rob

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-05-30 11:25

RobFerrer, can you try the most recent nightly snapshot?
you can easily upgrade to it, see the instructions in README.html and the FAQ.

http://galleryupdates.jpmullan.com

and if the problem persists, please edit gallery2/modules/core/classes/helpers/GalleryCharsetHelper_simple.class:

after

/* @suppress windows warning: "nl_langinfo() is not supported in this PHP build" */
	    $sourceEncoding = @$phpVm->nl_langinfo(CODESET);

please add:

$gallery->debug('GalleryCharsetHelper_simple::detectSystemCharset, nl_langinfo returned: "' .
			    $sourceEncoding . '"');

and after $lcTable = explode(';', $phpVm->setlocale(LC_ALL, '0'));please add:

	    $gallery->debug('GalleryCharsetHelper_simple::detectSystemCharset, setlocale returned: "' .
			    implode(';', $lcTable) . '"');

then turn on immediate (not buffered!) debug mode in config.php and let us see the output. (search for GalleryCharsetHelper in the output, we only need those lines . thanks.

 
RobFerrer

Joined: 2005-03-10
Posts: 33
Posted: Mon, 2005-05-30 15:03

The latest build didn't help (although see below), so made the changes as requested.

I think the line you need is:

Quote:
GalleryCharsetHelper_simple::detectSystemCharset, nl_langinfo returned: "ISO8859-1"

Which seems to be output once, the first time a date is displayed.

Probably unrelated, but I got an error message when updating:

Quote:
Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 498 bytes) in /usr/home/yuccbb/gallery2/lib/adodb/adodb-lib.inc.php on line 816

I increased the memory limit and re-did that step and it all worked fine. Should I submit this elsewhere?

Thanks

Rob

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Mon, 2005-05-30 16:43

Now try adding $sourceEncoding = 'ISO-8859-1'; in the code and see if that is the charset value it should be using.

 
RobFerrer

Joined: 2005-03-10
Posts: 33
Posted: Mon, 2005-05-30 17:29

I replaced the line
$sourceEncoding = @$phpVm->nl_langinfo(CODESET);

with the line

$sourceEncoding = 'ISO-8859-1';

and it all seems to work now.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-05-30 17:40

so, as a fix, we should normalize ISO8859-* to ISO-8859-* in GalleryCharsetHelper_simple::detectSystemCharset, right?

 
RobFerrer

Joined: 2005-03-10
Posts: 33
Posted: Mon, 2005-05-30 18:43

I don't fully understand what this is all doing, but it looks like that would fix my problem anyway.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-05-30 18:54

RobFerrer, don't think so. please update the other topic.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Mon, 2005-05-30 19:06

valiant, do you think we should have a separate "switch" for mapping nl_langinfo results, or move the existing switch outside that else block and put the new mapping there?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-05-30 19:32

i'd add a

$sourceEncoding = str_replace('ISO8859', 'ISO-8859', $sourceEncoding);

just before the GalleryDataCache::put($cacheKey, $sourceEncoding);

do you think that's too narrow, just looking for ISO8859?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Mon, 2005-05-30 21:41

that seems fine, catch any other -# suffixes in same check.. but i'd like to keep our mappings grouped together and well commented.. if you think it's ok, maybe move the existing switch outside that else block and put it next to this new bit you're adding.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-05-31 05:07

mindless, it's ok if you do it ;)
seriously, i can't / shouldn't work on g2 1,2 days.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2005-05-31 16:17

ok, change committed to cvs.

 
RobFerrer

Joined: 2005-03-10
Posts: 33
Posted: Wed, 2005-06-01 09:47

Latest version from CVS works great for me.

Off topic I'm afraid, but I didn't have to run any upgraders - is that normal?

Thanks to everyone working on this project.

Rob

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-06-01 10:07

RobFerrer, great.

@upgrades: depends: if your last update was only a day ago or so, then this is normal. it starts the upgrader only for "major" upgrades, i.e. when we changed something in the core module that requires a database / config file / ... change.

 
Windsor

Joined: 2006-03-16
Posts: 1
Posted: Thu, 2006-03-16 22:10

Forgive me for dredging this thread out of the archives.. I just installed everything on a Solaris9 box and had the same problem. Google led me here. :)

I did some debugging as requested above and fixed the problem. Here's the patch, if you wish...

: atlas; gdiff -u GalleryCharsetHelper_simple.class.FCS GalleryCharsetHelper_simple.class
--- GalleryCharsetHelper_simple.class.FCS       2006-03-16 15:45:06.957996000 -0600
+++ GalleryCharsetHelper_simple.class   2006-03-16 16:01:00.940157000 -0600
@@ -88,6 +88,9 @@
        case '1251':   /* Windows XP has LC_CTYPE=Russian_Russia.1251 */
            $sourceEncoding = 'CP1251';
            break;
+       case '646':   /* Solaris iconv returns "646" for ASCII */
+           $sourceEncoding = 'ASCII';
+           break;
        }
        /* FreeBSD may return charset with missing hyphen from nl_langinfo */
        $sourceEncoding = str_replace('ISO8859', 'ISO-8859', $sourceEncoding);
: atlas; pwd
.../modules/core/classes/helpers
 
treksler

Joined: 2004-10-18
Posts: 8
Posted: Fri, 2006-09-22 22:13

thanks Windsor
that fixed it for me as well on solaris 10

has this been applied?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2006-09-22 23:18

yes.. this is not in 2.1.x, but it is in current svn/will be in 2.2