[Mesa-dev] Bogus use of '#' in a macro definition (was: Re: Mesa (master): 29 new commits)

Thomas DEBESSE dev at illwieckz.net
Tue Nov 1 03:31:25 UTC 2016


Thread reference:
https://lists.freedesktop.org/archives/mesa-dev/2014-July/064410.html

On 07/31/2014 11:01:29 PDT Carl Worth writes:
> Ian Romanick <idr at freedesktop.org> writes:
> > On 07/31/2014 12:14 AM, Michel Dänzer wrote:
> >>
> >> FYI, this change broke the game Reaction Quake, see the failure output
> >> below. I don't know if this is a bug in this change or in the game, so
> >> I'm reporting it here.
>
> Hi Michel,
>
> Thanks very much for reporting this failure. It's certainly an
> interesting one.
>
> >> #define USE_DISCARD#line 0
> >
> > Something is seriously wrong here.
>
> The above line in the shader does seem to be what is triggering the
> error you noticed:
>
> >> 0:46(20): preprocessor error: syntax error, unexpected HASH_TOKEN,
expecting NEWLINE

On 07/31/2014 12:14 AM, Michel Dänzer wrote:
> > attribute vec4 attr_Position;
> > attribute vec3 attr_Normal;
> >
> > un
> > form mat4   u_ModelViewProjectionMatrix;
>
> This also looks bogus.
>
> Is this a bad copy-and-paste, or ... ?

It's not a bug in Mesa nor in GLSL shader, it's a bug in Reaction itself
which was already broken but doing weird things silently instead of
aborting. These commits do not introduced regressions on that part.

If you open the binary in a text editor you can see the strings are ok:

```
3242 #define USE_DISCARD^@^@^@^@^@attribute vec4 attr_Position;
3243 attribute vec3 attr_Normal;
3244
3245 uniform mat4   u_ModelViewProjectionMatrix;
```

same in hexdump:

```
000de370  55 53 45 5f 44 49 53 43  41 52 44 00 00 00 00 00
 |USE_DISCARD.....|
000de380  61 74 74 72 69 62 75 74  65 20 76 65 63 34 20 61  |attribute vec4
a|
000de390  74 74 72 5f 50 6f 73 69  74 69 6f 6e 3b 0d 0a 61
 |ttr_Position;..a|
000de3a0  74 74 72 69 62 75 74 65  20 76 65 63 33 20 61 74  |ttribute vec3
at|
000de3b0  74 72 5f 4e 6f 72 6d 61  6c 3b 0d 0a 0d 0a 75 6e
 |tr_Normal;....un|
000de3c0  69 66 6f 72 6d 20 6d 61  74 34 20 20 20 75 5f 4d  |iform mat4
u_M|
000de3d0  6f 64 65 6c 56 69 65 77  50 72 6f 6a 65 63 74 69
 |odelViewProjecti|
000de3e0  6f 6e 4d 61 74 72 69 78  3b 0d 0a 76 61 72 79 69
 |onMatrix;..varyi|
```

There is no `USE_DISCARD#Line0` but `USE_DISCARD\0` and no `un\nform` but
`uniform`

It looks like to be a bug in the code itself, some part of this shader is
generated at runtime and some memory corruption occurs, so it's probably a
classic string boundary issue, see this line:

https://github.com/ReactionQuake3/reaction/blob/a35d0a7c9c3062466edba3e42112e76bc9bcf6dd/code/renderergl2/tr_glsl.c#L1145

It's not a bug on Mesa's side, and there is no need to handle this case,
this case is Mesa parsing a corrupted file.

--
Thomas Debesse
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20161101/ef30f9bd/attachment.html>


More information about the mesa-dev mailing list