瀏覽代碼

Improve syncing, fix segfault

Lack of clamping while reading a pixel from a palette resulted in reading invalid memory
tags/v1.8.0
Xerbo 4 年之前
父節點
當前提交
e6674512e3
共有 2 個檔案被更改,包括 10 行新增3 行删除
  1. +8
    -1
      dsp.c
  2. +2
    -2
      pngio.c

+ 8
- 1
dsp.c 查看文件

@@ -209,7 +209,6 @@ int getpixelv(float *pvbuff, int count) {
}

// Get an entire row of pixels, aligned with sync markers
// FIXME: loses sync easily
int getpixelrow(float *pixelv, int nrow, int *zenith, int reset) {
static float pixels[PixelLine + SyncFilterLen];
static int npv;
@@ -256,6 +255,7 @@ int getpixelrow(float *pixelv, int nrow, int *zenith, int reset) {

if (synced < 8) {
int mshift;
static int lastmshift;

if (npv < PixelLine + SyncFilterLen) {
res = getpixelv(&(pixelv[npv]), PixelLine + SyncFilterLen - npv);
@@ -276,6 +276,13 @@ int getpixelrow(float *pixelv, int nrow, int *zenith, int reset) {
}
}

// Stop rows dissapearing into the void
int mshiftOrig = mshift;
if(abs(lastmshift-mshift) > 3 && nrow != 0){
mshift = 0;
}
lastmshift = mshiftOrig;
// If we are already as aligned as we can get, just continue
if (mshift == 0) {
synced++;


+ 2
- 2
pngio.c 查看文件

@@ -294,8 +294,8 @@ int applyUserPalette(float **prow, int nrow, char *filename, rgb_t **crow){

for(int y = 0; y < nrow; y++){
for(int x = 0; x < CH_WIDTH; x++){
int cha = prow[y][x + CHA_OFFSET];
int chb = prow[y][x + CHB_OFFSET];
int cha = CLIP(prow[y][x + CHA_OFFSET], 0, 255);
int chb = CLIP(prow[y][x + CHB_OFFSET], 0, 255);
crow[y][x + CHA_OFFSET] = pal_row[chb][cha];
}
}


Loading…
取消
儲存