Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix "out of bounds" undefined behavior #16975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions extern/agg24-svn/include/agg_pixfmt_gray.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,13 @@ namespace agg
typedef typename color_type::calc_type calc_type;
enum
{
num_components = 1,
pix_width = sizeof(value_type) * Step,
pix_step = Step,
pix_offset = Offset,
};
struct pixel_type
{
value_type c[num_components];
value_type c[pix_step];

void set(value_type v)
{
Expand All @@ -167,22 +166,22 @@ namespace agg

pixel_type* next()
{
return (pixel_type*)(c + pix_step);
return this + 1;
}

const pixel_type* next() const
{
return (const pixel_type*)(c + pix_step);
return this + 1;
}

pixel_type* advance(int n)
{
return (pixel_type*)(c + n * pix_step);
return this + n;
}

const pixel_type* advance(int n) const
{
return (const pixel_type*)(c + n * pix_step);
return this + n;
}
};

Expand Down
11 changes: 5 additions & 6 deletions extern/agg24-svn/include/agg_pixfmt_rgb.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,13 @@ namespace agg
typedef typename color_type::calc_type calc_type;
enum
{
num_components = 3,
pix_step = Step,
pix_offset = Offset,
pix_width = sizeof(value_type) * pix_step
};
struct pixel_type
{
value_type c[num_components];
value_type c[pix_step];

void set(value_type r, value_type g, value_type b)
{
Expand Down Expand Up @@ -230,22 +229,22 @@ namespace agg

pixel_type* next()
{
return (pixel_type*)(c + pix_step);
return this + 1;
}

const pixel_type* next() const
{
return (const pixel_type*)(c + pix_step);
return this + 1;
}

pixel_type* advance(int n)
{
return (pixel_type*)(c + n * pix_step);
return this + n;
}

const pixel_type* advance(int n) const
{
return (const pixel_type*)(c + n * pix_step);
return this + n;
}
};

Expand Down
22 changes: 10 additions & 12 deletions extern/agg24-svn/include/agg_pixfmt_rgba.h
Original file line number Diff line number Diff line change
Expand Up @@ -1515,13 +1515,12 @@ namespace agg
typedef typename color_type::calc_type calc_type;
enum
{
num_components = 4,
pix_step = 4,
pix_width = sizeof(value_type) * pix_step,
};
struct pixel_type
{
value_type c[num_components];
value_type c[pix_step];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should change, as it makes the rgba file inconsistent with the rgb one, and semantically these are different things.

Copy link
Contributor Author

@vitalybuka vitalybuka Apr 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we change them as well? Looks like this way code is simpler and compliant.
Then num_components is not used anywhere, but I can return it back if you like.
PTAL

Copy link

@tkoeppe tkoeppe Apr 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QuLogic : Has this point been resolved? (I don't have any opinion either way, but I wanted to make sure this isn't a blocker.)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(For what it's worth, if it is easier to land this overall fix without chaning the bounds here, I'd welcome that as a simpler first step; the deduplication of these two redundant enumerators could be a separate PR.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like as small as possible patches as well. Still here to use "this + 1" we need array size to be the "pix_step" not "num_components". Then num_components is unused. So the best I can do is moving lines with "- num_components = ..." into a separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure who you're tagging there; as you can see I've already approved.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vitalybuka: Ah of course, Step could be not 1... say, is the current code correct when Step is not 1? In that case the current code's next would skip over some array elements, right?


void set(value_type r, value_type g, value_type b, value_type a)
{
Expand Down Expand Up @@ -1555,22 +1554,22 @@ namespace agg

pixel_type* next()
{
return (pixel_type*)(c + pix_step);
return this + 1;
}

const pixel_type* next() const
{
return (const pixel_type*)(c + pix_step);
return this + 1;
}

pixel_type* advance(int n)
{
return (pixel_type*)(c + n * pix_step);
return this + n;
}

const pixel_type* advance(int n) const
{
return (const pixel_type*)(c + n * pix_step);
return this + n;
}
};

Expand Down Expand Up @@ -2193,13 +2192,12 @@ namespace agg
typedef typename color_type::calc_type calc_type;
enum
{
num_components = 4,
pix_step = 4,
pix_width = sizeof(value_type) * pix_step,
};
struct pixel_type
{
value_type c[num_components];
value_type c[pix_step];

void set(value_type r, value_type g, value_type b, value_type a)
{
Expand Down Expand Up @@ -2233,22 +2231,22 @@ namespace agg

pixel_type* next()
{
return (pixel_type*)(c + pix_step);
return this + 1;
}

const pixel_type* next() const
{
return (const pixel_type*)(c + pix_step);
return this + 1;
}

pixel_type* advance(int n)
{
return (pixel_type*)(c + n * pix_step);
return this + n;
}

const pixel_type* advance(int n) const
{
return (const pixel_type*)(c + n * pix_step);
return this + n;
}
};

Expand Down