OSDN Git Service

[Qt][OpenGL] Fix buffer overflow when changing VM's screen size.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Thu, 14 Jun 2018 18:43:39 +0000 (03:43 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Thu, 14 Jun 2018 18:43:39 +0000 (03:43 +0900)
source/src/qt/gui/gl2/qt_glutil_gl2_0.cpp
source/src/qt/gui/gl3/qt_glutil_gl3_0.cpp
source/src/qt/gui/gles2/qt_glutil_gles_2.cpp

index eee1fe5..cc046f5 100644 (file)
@@ -1262,8 +1262,15 @@ void GLDraw_2_0::do_set_texture_size(QImage *p, int w, int h)
                                         vertexFormat, 4);
                p_wid->doneCurrent();
        }               
-       this->doSetGridsHorizonal(h, false);
+       if(w > using_flags->get_real_screen_width()) {
+               w = using_flags->get_real_screen_width();
+       }                       
+       if(h > using_flags->get_real_screen_height()) {
+               h = using_flags->get_real_screen_height();
+       }
        this->doSetGridsVertical(w, false);
+       this->doSetGridsHorizonal(h, false);
+
 }
 
 void GLDraw_2_0::do_set_horiz_lines(int lines)
index 492c445..c4f140f 100644 (file)
@@ -1465,6 +1465,12 @@ void GLDraw_3_0::do_set_texture_size(QImage *p, int w, int h)
                                         main_pass->getVertexBuffer(),
                                         vertexFormat, 4);
                
+               if(w > using_flags->get_real_screen_width()) {
+                       w = using_flags->get_real_screen_width();
+               }                       
+               if(h > using_flags->get_real_screen_height()) {
+                       h = using_flags->get_real_screen_height();
+               }
                this->doSetGridsHorizonal(h, false);
                this->doSetGridsVertical(w, false);
                p_wid->doneCurrent();
index 9f1e8d2..4b0a2a7 100644 (file)
@@ -131,6 +131,7 @@ void GLDraw_ES_2::initBitmapVertex(void)
 void GLDraw_ES_2::initFBO(void)
 {
        glHorizGrids = (GLfloat *)malloc(sizeof(float) * (using_flags->get_real_screen_height() + 2) * 6);
+
        if(glHorizGrids != NULL) {
                doSetGridsHorizonal(using_flags->get_real_screen_height(), true);
        }
@@ -437,7 +438,7 @@ void GLDraw_ES_2::updateGridsVAO(QOpenGLBuffer *bp,
                        bp->allocate((number + 1) * sizeof(GLfloat) * 3 * 2);
                }
                if(tp != NULL) {
-                       bp->write(0, tp, (number + 1) * sizeof(GLfloat) * 3 * 2);
+                       bp->write(0, tp, number * sizeof(GLfloat) * 3 * 2);
                }
                bp->release();
                vp->release();
@@ -502,6 +503,7 @@ void GLDraw_ES_2::doSetGridsHorizonal(int lines, bool force)
 {
        if((lines == vert_lines) && !force) return;
        GLDraw_2_0::doSetGridsHorizonal(lines, force);
+
        updateGridsVAO(grids_horizonal_buffer,
                                   grids_horizonal_vertex,
                                   glHorizGrids,
@@ -1370,6 +1372,12 @@ void GLDraw_ES_2::do_set_texture_size(QImage *p, int w, int h)
                                         main_pass->getVertexBuffer(),
                                         vertexFormat, 4);
                
+               if(w > using_flags->get_real_screen_width()) {
+                       w = using_flags->get_real_screen_width();
+               }                       
+               if(h > using_flags->get_real_screen_height()) {
+                       h = using_flags->get_real_screen_height();
+               }
                this->doSetGridsHorizonal(h, false);
                this->doSetGridsVertical(w, false);
                p_wid->doneCurrent();