[Mesa-dev] [Mesa-stable] [PATCH 2/7] intel/isl: Add bounds-checking assertions for the format_info table

Jason Ekstrand jason at jlekstrand.net
Thu Jun 7 22:59:44 UTC 2018


On Thu, Jun 7, 2018 at 3:45 PM, Mark Janes <mark.a.janes at intel.com> wrote:

> This is cc'd to stable, but causes compile errors when to stable
> branches:
>
> src/intel/isl/isl_format.c:372:20: error: ‘ISL_NUM_FORMATS’ undeclared
> (first use in this function); did you mean ‘ISL_UFLOAT’?
>
> Is it dependent on another patch?
>

It's dependent on patch 1 which was also CCd to stable.

--Jason



> Jason Ekstrand <jason at jlekstrand.net> writes:
>
> > We follow the same convention as isl_format_get_layout in having two
> > assertions to ensure that only valid formats are passed in.  We also
> > check against the array size of the table because some valid formats
> > such as CCS formats will may be past the end of the table.  This fixes
> > some potential out-of-bounds array access even in valid cases.
> >
> > Cc: mesa-stable at lists.freedesktop.org
> > ---
> >  src/intel/isl/isl_format.c | 24 ++++++++++++++++--------
> >  1 file changed, 16 insertions(+), 8 deletions(-)
> >
> > diff --git a/src/intel/isl/isl_format.c b/src/intel/isl/isl_format.c
> > index 52997cf2ebb..968f981cdee 100644
> > --- a/src/intel/isl/isl_format.c
> > +++ b/src/intel/isl/isl_format.c
> > @@ -374,11 +374,19 @@ format_gen(const struct gen_device_info *devinfo)
> >     return devinfo->gen * 10 + (devinfo->is_g4x || devinfo->is_haswell)
> * 5;
> >  }
> >
> > +static bool
> > +format_info_exists(enum isl_format format)
> > +{
> > +   assert(format != ISL_FORMAT_UNSUPPORTED);
> > +   assert(format < ISL_NUM_FORMATS);
> > +   return format < ARRAY_SIZE(format_info) &&
> format_info[format].exists;
> > +}
> > +
> >  bool
> >  isl_format_supports_rendering(const struct gen_device_info *devinfo,
> >                                enum isl_format format)
> >  {
> > -   if (!format_info[format].exists)
> > +   if (!format_info_exists(format))
> >        return false;
> >
> >     return format_gen(devinfo) >= format_info[format].render_target;
> > @@ -388,7 +396,7 @@ bool
> >  isl_format_supports_alpha_blending(const struct gen_device_info
> *devinfo,
> >                                     enum isl_format format)
> >  {
> > -   if (!format_info[format].exists)
> > +   if (!format_info_exists(format))
> >        return false;
> >
> >     return format_gen(devinfo) >= format_info[format].alpha_blend;
> > @@ -398,7 +406,7 @@ bool
> >  isl_format_supports_sampling(const struct gen_device_info *devinfo,
> >                               enum isl_format format)
> >  {
> > -   if (!format_info[format].exists)
> > +   if (!format_info_exists(format))
> >        return false;
> >
> >     if (devinfo->is_baytrail) {
> > @@ -431,7 +439,7 @@ bool
> >  isl_format_supports_filtering(const struct gen_device_info *devinfo,
> >                                enum isl_format format)
> >  {
> > -   if (!format_info[format].exists)
> > +   if (!format_info_exists(format))
> >        return false;
> >
> >     if (devinfo->is_baytrail) {
> > @@ -464,7 +472,7 @@ bool
> >  isl_format_supports_vertex_fetch(const struct gen_device_info *devinfo,
> >                                   enum isl_format format)
> >  {
> > -   if (!format_info[format].exists)
> > +   if (!format_info_exists(format))
> >        return false;
> >
> >     /* For vertex fetch, Bay Trail supports the same set of formats as
> Haswell
> > @@ -483,7 +491,7 @@ bool
> >  isl_format_supports_typed_writes(const struct gen_device_info *devinfo,
> >                                   enum isl_format format)
> >  {
> > -   if (!format_info[format].exists)
> > +   if (!format_info_exists(format))
> >        return false;
> >
> >     return format_gen(devinfo) >= format_info[format].typed_write;
> > @@ -504,7 +512,7 @@ bool
> >  isl_format_supports_typed_reads(const struct gen_device_info *devinfo,
> >                                  enum isl_format format)
> >  {
> > -   if (!format_info[format].exists)
> > +   if (!format_info_exists(format))
> >        return false;
> >
> >     return format_gen(devinfo) >= format_info[format].typed_read;
> > @@ -542,7 +550,7 @@ bool
> >  isl_format_supports_ccs_e(const struct gen_device_info *devinfo,
> >                            enum isl_format format)
> >  {
> > -   if (!format_info[format].exists)
> > +   if (!format_info_exists(format))
> >        return false;
> >
> >     /* For simplicity, only report that a format supports CCS_E if blorp
> can
> > --
> > 2.17.1
> >
> > _______________________________________________
> > mesa-stable mailing list
> > mesa-stable at lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/mesa-stable
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180607/959c43ad/attachment.html>


More information about the mesa-dev mailing list