Tk Source Code

View Ticket
Login
Ticket UUID: 9983b847b7d734e21b4f3c047a04f5ce106a3130
Title: Color string with invalid hex digit parses without error on OS X
Type: Bug Version: trunk, tip-166
Submitter: fvogel Created on: 2017-03-28 06:18:39
Subsystem: 30. Color Names Assigned To: simonbachmann
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2017-04-13 21:41:15
Resolution: Duplicate Closed By: ferrieux
    Closed on: 2017-04-13 21:41:15
Description:

On OS X, running the test suite for the img*.test files triggers only one failure:

==== imgListFormat-6.19 ParseColor: invalid color: not a hex digit FAILED
==== Contents of test case:

     photo1 put {#[email protected] #[email protected]}

---- Test completed normally; Return code was: 0
---- Return code should have been one of: 1
==== imgListFormat-6.19 FAILED
This is repeatable each time on OS X Sierra 10.12.3

User Comments: ferrieux added on 2017-04-13 21:41:15:
Excellent, and thanks for the full story !

simonbachmann added on 2017-04-13 18:43:56:

That's right, this bug was definitely a duplicate of [f0188aca9e] and is fixed now.

Since it's not exactly obvious at first glance what was going on here, and for future reference, here's a detailed description of the problem:

The root cause of both bugs was in the function XParseColor() in xlib/xcolors.c (needed on platforms that don't have X11 natively). That function would stop at the fist invalid hex digit of a #XXX color string and - if 3, 6, 9 or 12 valid digits were parsed - return success istead of failing.

On all platforms, a hex-color string gets passed verbatim to TkParseColor() in generic/tkColors.c.

On Windows, that function is just a preprocessor macro that expands to XparseColor(), i.e. the color string goes to XParseColor() without modifications. That's why something like #ABCG would (incorrectly) parse without error (3 valid hex digits, rest is discarded), but not #ABCDEG (5 valid digits).

On Mac and other Unixes, the actual TkParseColor() in generic/tkColor.c function is used. That function does a partial parsing of hex colors: - It checks how many chars the string has and fails if it's not 3, 6, ... - It does NOT check if the chars are valid hex digits - It expands the color string to 12 hex digits - The resulting string is passed to XParseColor().

For this reason a color name #ABCG would not trigger the bug on OS X (it has 4 chars). The color string #ABCDEG, OTOH, is considered valid by TkParseColor() (6 chars) and expanded to #ABABCDCDEGEG. That's nine valid hex digits before the first non-hex char and thus parsed as correct by the buggy XParseColor().

On Systems that have X11, the bug does not show at all, since the native XParseColor() library function works as expected.


fvogel added on 2017-04-11 19:43:50:

1. With both trunk and tip-166 branch,

  winfo rgb . #ABCDEG

returns

  invalid color name "#ABCDEG"

2. With both trunk and tip-166 branch,

  make -C ./macosx test TESTFLAGS="-file color.test"

returns no error. The output is:

Total: 21  Passed: 4  Skipped: 17  Failed: 0

These both tests seem to provide the expected results, isn't it? So the bug is no longer present, meaning that the present ticket is a duplicate of [f0188aca9e] that you have already fixed?


simonbachmann added on 2017-04-11 17:19:41:
Sorry for not being clear on what to test.

The most direct way to test for this bug is the command

  winfo rgb . #ABCDEG

Which should obviously fail with an error message and not return some (incorrect) rgb values.

I would be grateful if you could:
1) run the above command
2) run the test suite with TESTFLAGS="-file color.test"
On both trunk and tip-166.

Thanks for your help on this!

fvogel added on 2017-04-09 20:07:24:

In both trunk and in tip-166 branch, the test suite run through:

make -C ./macosx test TESTFLAGS="-file img*.test"
now runs without any error.

This is how I produced the problem in my original report. Is it what you wanted me to test? It's unclear to me what you meant by "does the problem still persist", because test imgListFormat-6.19 has disappeared from branch tip-166 with [a6dca2ed].


simonbachmann (claiming to be Simon Bachmann) added on 2017-04-09 18:16:32:

Waitasec! This might actually be a duplicate of [f0188aca9e].

Does the problem still persist with the latest version of trunk/tip-166?


fvogel added on 2017-04-09 11:39:12:
tk windowingystem returns "aqua" on the system I used to report below.

simonbachmann added on 2017-04-09 10:40:41:

Is this on Aqua or X11?

If it's X11, it probably isn't even a Tk bug. The problem might be in the X11 implementation for OS X.

BTW, the tests I added for [d8a75c2f] should bring up this issue.


fvogel added on 2017-04-09 08:17:16:

With tip-166 branch and trunk the output is the same:

% winfo rgb . #ABCDEF
43947 52685 61423
% winfo rgb . #ABCDEG
43946 48347 52716
%

So yes, not related to tip-166.


simonbachmann added on 2017-04-08 09:34:35:
I'm pretty sure this bug has nothing to do with the changes introduced by tip-166. 

What's the result of these commands, branch 'tip-166' compared to 'trunk'?

  winfo rgb . #ABCDEF
  winfo rgb . #ABCDEG

fvogel added on 2017-04-06 20:08:31:

Results for OS X, at the current bleeding edge of branch tip-166:

% image create photo p
p
% p put {#[email protected] #[email protected]}
% p data -format {default -colorformat list}
{{171 205 239 252}} {{171 188 205 252}}
% p put {#[email protected] #[email protected]}
invalid color name "#[email protected]"
% p data -format {default -colorformat list}
{{171 205 239 252}} {{171 188 205 252}}
% p put {#ABCDEF #ABCDEG}
% p data -format {default -colorformat list}
{{171 205 239 255}} {{171 188 205 255}}
% p put {#ABC #ABG}
invalid color name "#ABG"
% p data -format {default -colorformat list}
{{171 205 239 255}} {{171 188 205 255}}
%


simonbachmann added on 2017-04-05 21:32:05:

I came to the same conclusion while fixing [7c49a7f594], the issues are not related.

This one still puzzles me, though.

Could you report the results of these commands on OS X?

  image create photo p
  p put {#[email protected] #[email protected]}
  p data -format {default -colorformat list}
  p put {#[email protected] #[email protected]}
  p data -format {default -colorformat list}
  p put {#ABCDEF #ABCDEG}
  p data -format {default -colorformat list}
  p put {#ABC #ABG}
  p data -format {default -colorformat list}
Thaks!


fvogel added on 2017-04-05 04:20:05:

Some feedback: [4f9516ab] provides no improvement on this issue. Situation on OS X is unchanged. On OS X I still get, with tip-166 branch:

% image create photo p
p
% p put {{#abcd}}
% p put {{#abcg}}
couldn't recognize image data
% p data
{#bbccdd}
%

However the "Run-Time Check Failure #2 - Stack around the variable 'dummy' was corrupted." on Windows (see my previous message) is now gone, that was the problem described in [7c49a7f594], which got fixed by [4f9516ab]. The present ticket definitely is an issue different from [7c49a7f594].


fvogel added on 2017-04-02 19:15:56:

BTW, on Windows, in tip-166 branch but not in trunk, when running the line p put {{#abcd}}, there is a "Run-Time Check Failure #2 - Stack around the variable 'dummy' was corrupted."

Breaking shows the following call stack:

 	tk87tg.dll!StringMatchDef(Tcl_Obj * data=0x004b6aa8, Tcl_Obj * formatString=0x00000000, int * widthPtr=0x002bfb34, int * heightPtr=0x002bfb28, Tcl_Interp * interp=0x00485bd0)  Line 415 + 0xf bytes	C
 	tk87tg.dll!MatchStringFormat(Tcl_Interp * interp=0x00485bd0, Tcl_Obj * data=0x004b6aa8, Tcl_Obj * formatObj=0x00000000, Tk_PhotoImageFormat * * imageFormatPtr=0x002bfb44, int * widthPtr=0x002bfb34, int * heightPtr=0x002bfb28, int * oldformat=0x002bfb18)  Line 2630 + 0x36 bytes	C
 	tk87tg.dll!ImgPhotoCmd(void * clientData=0x03f2e168, Tcl_Interp * interp=0x00485bd0, int objc=3, Tcl_Obj * const * objv=0x0048cf34)  Line 875 + 0x30 bytes	C
 	tcl87tg.dll!Dispatch(void * * data=0x004b9e24, Tcl_Interp * interp=0x00485bd0, int result=0)  Line 4376 + 0x15 bytes	C
 	tcl87tg.dll!TclNRRunCallbacks(Tcl_Interp * interp=0x00485bd0, int result=0, NRE_callback * rootPtr=0x00000000)  Line 4409 + 0x14 bytes	C
 	tcl87tg.dll!TclEvalObjEx(Tcl_Interp * interp=0x00485bd0, Tcl_Obj * objPtr=0x00539278, int flags=131072, const CmdFrame * invoker=0x00000000, int word=0)  Line 5976 + 0x11 bytes	C
 	tcl87tg.dll!Tcl_EvalObjEx(Tcl_Interp * interp=0x00485bd0, Tcl_Obj * objPtr=0x00539278, int flags=131072)  Line 5957 + 0x15 bytes	C
 	tcl87tg.dll!Tcl_RecordAndEvalObj(Tcl_Interp * interp=0x00485bd0, Tcl_Obj * cmdPtr=0x00539278, int flags=131072)  Line 189 + 0x17 bytes	C
 	tcl87tg.dll!StdinProc(void * clientData=0x002bfecc, int mask=2)  Line 811 + 0x12 bytes	C
 	tcl87tg.dll!Tcl_NotifyChannel(Tcl_Channel_ * channel=0x004bb508, int mask=2)  Line 8319 + 0x1b bytes	C
 	tcl87tg.dll!ConsoleEventProc(Tcl_Event * evPtr=0x0051fb08, int flags=-3)  Line 964 + 0x16 bytes	C
 	tcl87tg.dll!Tcl_ServiceEvent(int flags=-3)  Line 670 + 0xd bytes	C
 	tcl87tg.dll!Tcl_DoOneEvent(int flags=-3)  Line 967 + 0x9 bytes	C
 	tk87tg.dll!Tk_MainLoop()  Line 2148 + 0x11 bytes	C
 	tcl87tg.dll!Tcl_MainExW(int argc=-1, unsigned short * * argv=0x025c1bec, int (Tcl_Interp *)* appInitProc=0x004010a0, Tcl_Interp * interp=0x00485bd0)  Line 580 + 0x5 bytes	C
 	tclsh87tg.exe!wmain(int argc=1, unsigned short * * argv=0x025c1be8)  Line 129 + 0x25 bytes	C
 	tclsh87tg.exe!__tmainCRTStartup()  Line 579 + 0x19 bytes	C
 	tclsh87tg.exe!wmainCRTStartup()  Line 399	C


fvogel added on 2017-04-02 19:01:05:

On OS X I get:

With tip-166 branch:

% image create photo p
p
% p put {{#abcd}}
% p put {{#abcg}}
couldn't recognize image data
% p data
{#bbccdd}
%

With trunk:

% image create photo p
p
% p put {{#abcd}}
can't parse color "#abcd"
% p put {{#abcg}}
can't parse color "#abcg"
% p data
%

So :

- OS X shows different results compared to what you report for Windows
- OS X has different output in trunk and in tip-166 branch


simonbachmann (claiming to be Simon Bachmann) added on 2017-04-02 17:58:14:
I suspect this has nothing to do with the canges added for TIP 166. 

While I cannot test this on OS X, on Windows the problem seems to exist as well.

The results of the following commands is the same for Tk 8.5.13, 8.6.6, and 'trunk' from fossil:

  % image create photo p
  p
  % p put {{#abcd}}
  can't parse color "#abcd"
  % p put {{#abcg}}
  % --> no error!!
  % p data
  {#aabbcc}
  
Can you please check if you get the same results on OS X?