Skip to content
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

raw-tools/sony_arw/dcraw.c Buffer Overflow #565

Open
ksyang opened this issue Sep 30, 2023 · 0 comments
Open

raw-tools/sony_arw/dcraw.c Buffer Overflow #565

ksyang opened this issue Sep 30, 2023 · 0 comments

Comments

@ksyang
Copy link

ksyang commented Sep 30, 2023

Hi.

We discovered that the LibRaw/LibRaw@fd63302 vulnerability (https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-5808), discovered in LibRaw, affects the latest version of dcraw_hack.

System Configuration

FLIF Version: Master branch (commit 0074d6f)
Test environment : Ubuntu 22.04.2 LTS 64bit

Description

float CLASS find_green (int bps, int bite, int off0, int off1)
{
UINT64 bitbuf=0;
int vbits, col, i, c;
ushort img[2][2064];
double sum[]={0,0};
FORC(2) {
fseek (ifp, c ? off1:off0, SEEK_SET);
for (vbits=col=0; col < width; col++) {
for (vbits -= bps; vbits < 0; vbits += bite) {
bitbuf <<= bite;
for (i=0; i < bite; i+=8)
bitbuf |= (unsigned) (fgetc(ifp) << i);
}
img[c][col] = bitbuf << (64-bps-vbits) >> (64-bps);
}
}
FORC(width-1) {
sum[ c & 1] += ABS(img[0][c]-img[1][c+1]);
sum[~c & 1] += ABS(img[1][c]-img[0][c+1]);
}
return 100 * log(sum[0]/sum[1]);
}

In the above code, if the value of the col variable exceeds 2064, a stack buffer overflow occurs. The col value is determined by the value of width, but since there is no limit to the value of width, a stack buffer overflow vulnerability occurs.

$ ./FLIF/raw-tools/sony_arw/dcraw_hack ./files/test.raw
Segmentation fault (core dumped)

The vulnerability can be fixed by patching as follows.

 - double sum[]={0,0};
 + double sum[] = {0, 0};
 + if(width > 2064) return 0.f; // too wide

Due to issue upload file size limitations, the PoC is shared through Google Drive below.

PoC file : https://drive.google.com/file/d/1s5N0Ao2lAWO73bzVFmP6EMJ5LZ6Efo_Y/view?usp=drive_link

Credit : Seunghoon Woo & Kyeongseok Yang, CCS Lab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant