Skip to content

Commit

Permalink
Fixed an out of bounds bug in System.takeScreenshot.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinnegatamante committed Nov 8, 2021
1 parent 2d42c21 commit 5e638b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion doc/luaSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ class System{
*
* @note <b>ratio</b> must be between 0 and 255.
*/
void takeScreenshot(string filename, ImgFmt use_jpg, int ratio);
void takeScreenshot(string filename, ImgFmt format, int ratio);

/**
* Execute an URI call.
Expand Down
18 changes: 9 additions & 9 deletions source/luaSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ extern "C"{

#define COPY_BUFFER_SIZE 1024 * 1024

static int FORMAT_BMP = 0;
static int FORMAT_PNG = 1;
static int FORMAT_JPG = 2;
int FORMAT_BMP = 0;
int FORMAT_PNG = 1;
int FORMAT_JPG = 2;
static int FREAD = SCE_O_RDONLY;
static int FWRITE = SCE_O_WRONLY;
static int FCREATE = SCE_O_CREAT | SCE_O_WRONLY;
Expand Down Expand Up @@ -715,15 +715,15 @@ static int lua_screenshot(lua_State *L){
*(uint32_t*)&bmp_content[0x1A] = 0x00200001;
*(uint32_t*)&bmp_content[0x22] = ((param.pitch*param.height)<<2);
int x, y;
uint32_t* buffer = (uint32_t*)bmp_content;
uint32_t* buffer = (uint32_t*)&bmp_content[0x36];
uint32_t* framebuf = (uint32_t*)param.base;
for (y = 0; y<param.height; y++){
for (x = 0; x<param.pitch; x++){
buffer[x+y*param.pitch+0x36] = framebuf[x+(param.height-y)*param.pitch];
uint8_t *clr = (uint8_t*)&buffer[x+y*param.pitch+0x36];
uint8_t r = clr[1];
clr[1] = clr[3];
clr[3] = r;
buffer[x+y*param.pitch] = framebuf[x+(param.height-y)*param.pitch];
uint8_t *clr = (uint8_t*)&buffer[x+y*param.pitch];
uint8_t r = clr[0];
clr[0] = clr[2];
clr[2] = r;
}
}
sceIoWrite(fd, bmp_content, ((param.pitch*param.height)<<2)+0x36);
Expand Down

0 comments on commit 5e638b9

Please sign in to comment.