[Mesa-dev] [PATCH] glsl/blob: clear padding bytes

Timothy Arceri tarceri at itsqueeze.com
Thu Mar 9 09:42:17 UTC 2017


On 08/03/17 23:28, Grazvydas Ignotas wrote:
> (CCing some people who touched or reviewed blob)
> Ping. I think writing stale heap contents to cache should be avoided
> and this patch is an improvement.
>
> GraÅžvydas
>
> On Fri, Mar 3, 2017 at 1:59 AM, Grazvydas Ignotas <notasas at gmail.com> wrote:
>> Since blob is intended for serializing data, it's not a good idea to
>> leave padding holes with uninitialized data, which may leak heap
>> contents and hurt compression if the blob is later compressed, like
>> done by shader cache. Clear it.
>>
>> Signed-off-by: Grazvydas Ignotas <notasas at gmail.com>
>> ---
>> I don't know why blob bothers with aligning at all, maybe it's better
>> to just get rid of it and replace *(uint *) reads with memcpy?

Yeah I'm not sure what the thinking was. Maybe to try speed-up memcpys, 
I'm not sure if it really helps or not though.

Anyway this patch makes sense so I've pushed, thanks.

>>
>>  src/compiler/glsl/blob.c | 9 ++++++---
>>  1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/src/compiler/glsl/blob.c b/src/compiler/glsl/blob.c
>> index dd4341b..a7a5e65 100644
>> --- a/src/compiler/glsl/blob.c
>> +++ b/src/compiler/glsl/blob.c
>> @@ -70,10 +70,13 @@ align_blob(struct blob *blob, size_t alignment)
>>  {
>>     const size_t new_size = ALIGN(blob->size, alignment);
>>
>> -   if (! grow_to_fit (blob, new_size - blob->size))
>> -      return false;
>> +   if (blob->size < new_size) {
>> +      if (! grow_to_fit(blob, new_size - blob->size))
>> +         return false;
>>
>> -   blob->size = new_size;
>> +      memset(blob->data + blob->size, 0, new_size - blob->size);
>> +      blob->size = new_size;
>> +   }
>>
>>     return true;
>>  }
>> --
>> 2.7.4
>>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>


More information about the mesa-dev mailing list