Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit ff45ed4

Browse files
committed
[[ Bug 22085 ]] Fix use after release of dashes struct lengths field
This patch fixes an issue that arises when using the dashes offset opcode of the drawing library - the dashes struct's lengths field is meant to be re-used for the new dashes with offset, but it is actually released first, causing the passed-in lengths pointer to be invalid.
1 parent 830d558 commit ff45ed4

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

docs/notes/bugfix-22085.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Ensure dashes offset drawing library opcode works correctly

libgraphics/src/context.cpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,10 +1694,17 @@ void MCGContextSetStrokeCapStyle(MCGContextRef self, MCGCapStyle p_style)
16941694

16951695
void MCGContextSetStrokeDashOffset(MCGContextRef self, MCGFloat p_offset)
16961696
{
1697-
MCGContextSetStrokeDashes(self,
1698-
p_offset,
1699-
self->state->stroke_attr.dashes != nullptr ? self->state->stroke_attr.dashes->lengths : nullptr,
1700-
self->state->stroke_attr.dashes != nullptr ? self->state->stroke_attr.dashes->count : 0);
1697+
if (self->state->stroke_attr.dashes != nullptr)
1698+
{
1699+
MCGContextSetStrokeDashes(self,
1700+
p_offset,
1701+
self->state->stroke_attr.dashes->lengths,
1702+
self->state->stroke_attr.dashes->count);
1703+
}
1704+
else
1705+
{
1706+
MCGContextSetStrokeDashes(self, p_offset, nullptr, 0);
1707+
}
17011708
}
17021709

17031710
void MCGContextSetStrokeDashArray(MCGContextRef self, const MCGFloat *p_lengths, uindex_t p_arity)
@@ -1706,22 +1713,25 @@ void MCGContextSetStrokeDashArray(MCGContextRef self, const MCGFloat *p_lengths,
17061713
}
17071714

17081715
void MCGContextSetStrokeDashes(MCGContextRef self, MCGFloat p_phase, const MCGFloat *p_lengths, uindex_t p_arity)
1709-
{
1716+
{
17101717
if (!MCGContextIsValid(self))
17111718
return;
1712-
1713-
bool t_success;
1714-
t_success = true;
1715-
1719+
1720+
bool t_success = true;
1721+
1722+
MCGDashesRef t_dashes = nullptr;
17161723
if (t_success)
17171724
{
1725+
t_success = MCGDashesCreate(p_phase, p_lengths, p_arity, t_dashes);
1726+
}
1727+
1728+
if (t_success)
1729+
{
17181730
MCGDashesRelease(self -> state -> stroke_attr . dashes);
1719-
self -> state -> stroke_attr . dashes = NULL;
1720-
1721-
t_success = MCGDashesCreate(p_phase, p_lengths, p_arity, self -> state -> stroke_attr . dashes);
1722-
}
1723-
1724-
self -> is_valid = t_success;
1731+
self -> state -> stroke_attr . dashes = t_dashes;
1732+
}
1733+
1734+
self -> is_valid = t_success;
17251735
}
17261736

17271737
void MCGContextSetStrokePaintStyle(MCGContextRef self, MCGPaintStyle p_paint_style)

0 commit comments

Comments
 (0)