提交 39568aea 编写于 作者: L lbourges

8145055: Marlin renderer causes unaligned write accesses

Reviewed-by: flar, prr
上级 32a26a30
...@@ -156,8 +156,6 @@ public final class MarlinCache implements MarlinConst { ...@@ -156,8 +156,6 @@ public final class MarlinCache implements MarlinConst {
// rewritten to avoid division: // rewritten to avoid division:
|| (width * heightSubPixel) > || (width * heightSubPixel) >
((edgeSumDeltaY - heightSubPixel) << BLOCK_SIZE_LG); ((edgeSumDeltaY - heightSubPixel) << BLOCK_SIZE_LG);
// ((edgeSumDeltaY - heightSubPixel) * RLE_THRESHOLD);
// ((edgeSumDeltaY - heightSubPixel) << BLOCK_TH_LG);
if (doTrace && !useRLE) { if (doTrace && !useRLE) {
final float meanCrossings final float meanCrossings
...@@ -293,8 +291,10 @@ public final class MarlinCache implements MarlinConst { ...@@ -293,8 +291,10 @@ public final class MarlinCache implements MarlinConst {
// update row index to current position: // update row index to current position:
rowAAChunkIndex[row] = pos; rowAAChunkIndex[row] = pos;
// determine need array size (may overflow): // determine need array size:
final long needSize = pos + (px_bbox1 - px0); // for RLE encoding, position must be aligned to 4 bytes (int):
// align - 1 = 3 so add +3 and round-off by mask ~3 = -4
final long needSize = pos + ((px_bbox1 - px0 + 3) & -4);
// update next position (bytes): // update next position (bytes):
rowAAChunkPos = needSize; rowAAChunkPos = needSize;
...@@ -401,8 +401,7 @@ public final class MarlinCache implements MarlinConst { ...@@ -401,8 +401,7 @@ public final class MarlinCache implements MarlinConst {
// determine need array size: // determine need array size:
// pessimistic: max needed size = deltaX x 4 (1 int) // pessimistic: max needed size = deltaX x 4 (1 int)
final int maxLen = (to - from); final long needSize = initialPos + ((to - from) << 2);
final long needSize = initialPos + (maxLen << 2);
// update row data: // update row data:
OffHeapArray _rowAAChunk = rowAAChunk; OffHeapArray _rowAAChunk = rowAAChunk;
...@@ -465,6 +464,13 @@ public final class MarlinCache implements MarlinConst { ...@@ -465,6 +464,13 @@ public final class MarlinCache implements MarlinConst {
// note: last pixel exclusive (>= 0) // note: last pixel exclusive (>= 0)
// note: it should check X is smaller than 23bits (overflow)! // note: it should check X is smaller than 23bits (overflow)!
// check address alignment to 4 bytes:
if (doCheckUnsafe) {
if ((addr_off & 3) != 0) {
MarlinUtils.logInfo("Misaligned Unsafe address: " + addr_off);
}
}
// special case to encode entries into a single int: // special case to encode entries into a single int:
if (val == 0) { if (val == 0) {
_unsafe.putInt(addr_off, _unsafe.putInt(addr_off,
...@@ -521,6 +527,13 @@ public final class MarlinCache implements MarlinConst { ...@@ -521,6 +527,13 @@ public final class MarlinCache implements MarlinConst {
// note: last pixel exclusive (>= 0) // note: last pixel exclusive (>= 0)
// note: it should check X is smaller than 23bits (overflow)! // note: it should check X is smaller than 23bits (overflow)!
// check address alignment to 4 bytes:
if (doCheckUnsafe) {
if ((addr_off & 3) != 0) {
MarlinUtils.logInfo("Misaligned Unsafe address: " + addr_off);
}
}
// special case to encode entries into a single int: // special case to encode entries into a single int:
if (val == 0) { if (val == 0) {
_unsafe.putInt(addr_off, _unsafe.putInt(addr_off,
......
...@@ -40,6 +40,8 @@ interface MarlinConst { ...@@ -40,6 +40,8 @@ interface MarlinConst {
// log misc.Unsafe alloc/realloc/free // log misc.Unsafe alloc/realloc/free
static final boolean logUnsafeMalloc = enableLogs static final boolean logUnsafeMalloc = enableLogs
&& MarlinProperties.isLogUnsafeMalloc(); && MarlinProperties.isLogUnsafeMalloc();
// do check unsafe alignment:
static final boolean doCheckUnsafe = false;
// do statistics // do statistics
static final boolean doStats = enableLogs && MarlinProperties.isDoStats(); static final boolean doStats = enableLogs && MarlinProperties.isDoStats();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册