11/* ****************************************************************************
22* gta5view Grand Theft Auto V Profile Viewer
3- * Copyright (C) 2020 Syping
3+ * Copyright (C) 2020-2021 Syping
44*
55* This program is free software: you can redistribute it and/or modify
66* it under the terms of the GNU General Public License as published by
@@ -90,15 +90,20 @@ bool RagePhoto::load()
9090 quint32 format = charToUInt32LE (uInt32Buffer);
9191
9292 if (format == static_cast <quint32>(PhotoFormat::GTA5)) {
93- char photoHeader[256 ];
93+ char *photoHeader = static_cast <char *>(malloc (256 ));
94+ if (!photoHeader)
95+ return false ;
9496 size = dataBuffer.read (photoHeader, 256 );
95- if (size != 256 )
97+ if (size != 256 ) {
98+ free (photoHeader);
9699 return false ;
100+ }
97101 for (const QChar &photoChar : utf16LEToString (photoHeader, 256 )) {
98102 if (photoChar.isNull ())
99103 break ;
100104 p_photoString += photoChar;
101105 }
106+ free (photoHeader);
102107
103108 size = dataBuffer.read (uInt32Buffer, 4 );
104109 if (size != 4 )
@@ -142,11 +147,16 @@ bool RagePhoto::load()
142147 return false ;
143148 quint32 t_photoSize = charToUInt32LE (uInt32Buffer);
144149
145- char photoData[t_photoSize];
150+ char *photoData = static_cast <char *>(malloc (t_photoSize));
151+ if (!photoData)
152+ return false ;
146153 size = dataBuffer.read (photoData, t_photoSize);
147- if (size != t_photoSize)
154+ if (size != t_photoSize) {
155+ free (photoData);
148156 return false ;
157+ }
149158 p_photoData = QByteArray (photoData, t_photoSize);
159+ free (photoData);
150160
151161 dataBuffer.seek (p_jsonOffset + 264 );
152162 size = dataBuffer.read (markerBuffer, 4 );
@@ -160,15 +170,20 @@ bool RagePhoto::load()
160170 return false ;
161171 p_jsonBuffer = charToUInt32LE (uInt32Buffer);
162172
163- char jsonBytes[p_jsonBuffer];
173+ char *jsonBytes = static_cast <char *>(malloc (p_jsonBuffer));
174+ if (!jsonBytes)
175+ return false ;
164176 size = dataBuffer.read (jsonBytes, p_jsonBuffer);
165- if (size != p_jsonBuffer)
177+ if (size != p_jsonBuffer) {
178+ free (jsonBytes);
166179 return false ;
180+ }
167181 for (quint32 i = 0 ; i != p_jsonBuffer; i++) {
168182 if (jsonBytes[i] == ' \x00 ' )
169183 break ;
170184 p_jsonData += jsonBytes[i];
171185 }
186+ free (jsonBytes);
172187 QJsonDocument t_jsonDocument = QJsonDocument::fromJson (p_jsonData);
173188 if (t_jsonDocument.isNull ())
174189 return false ;
@@ -186,15 +201,20 @@ bool RagePhoto::load()
186201 return false ;
187202 p_titlBuffer = charToUInt32LE (uInt32Buffer);
188203
189- char titlBytes[p_titlBuffer];
204+ char *titlBytes = static_cast <char *>(malloc (p_titlBuffer));
205+ if (!titlBytes)
206+ return false ;
190207 size = dataBuffer.read (titlBytes, p_titlBuffer);
191- if (size != p_titlBuffer)
208+ if (size != p_titlBuffer){
209+ free (titlBytes);
192210 return false ;
211+ }
193212 for (const QChar &titlChar : QString::fromUtf8 (titlBytes, p_titlBuffer)) {
194213 if (titlChar.isNull ())
195214 break ;
196215 p_titleString += titlChar;
197216 }
217+ free (titlBytes);
198218
199219 dataBuffer.seek (p_descOffset + 264 );
200220 size = dataBuffer.read (markerBuffer, 4 );
@@ -208,15 +228,20 @@ bool RagePhoto::load()
208228 return false ;
209229 p_descBuffer = charToUInt32LE (uInt32Buffer);
210230
211- char descBytes[p_descBuffer];
231+ char *descBytes = static_cast <char *>(malloc (p_descBuffer));
232+ if (!descBytes)
233+ return false ;
212234 size = dataBuffer.read (descBytes, p_descBuffer);
213- if (size != p_descBuffer)
235+ if (size != p_descBuffer) {
236+ free (descBytes);
214237 return false ;
238+ }
215239 for (const QChar &descChar : QString::fromUtf8 (descBytes, p_descBuffer)) {
216240 if (descChar.isNull ())
217241 break ;
218242 p_descriptionString += descChar;
219243 }
244+ free (descBytes);
220245
221246 dataBuffer.seek (p_endOfFile + 260 );
222247 size = dataBuffer.read (markerBuffer, 4 );
@@ -243,12 +268,17 @@ bool RagePhoto::load()
243268 return false ;
244269 quint32 compressedSize = charToUInt32LE (uInt32Buffer);
245270
246- char compressedPhotoHeader[compressedSize];
271+ char *compressedPhotoHeader = static_cast <char *>(malloc (compressedSize));
272+ if (!compressedPhotoHeader)
273+ return false ;
247274 size = dataBuffer.read (compressedPhotoHeader, compressedSize);
248- if (size != compressedSize)
275+ if (size != compressedSize) {
276+ free (compressedPhotoHeader);
249277 return false ;
278+ }
250279 QByteArray t_photoHeader = QByteArray::fromRawData (compressedPhotoHeader, compressedSize);
251280 t_photoHeader = qUncompress (t_photoHeader);
281+ free (compressedPhotoHeader);
252282 if (t_photoHeader.isEmpty ())
253283 return false ;
254284 p_photoString = QString::fromUtf8 (t_photoHeader);
@@ -268,12 +298,17 @@ bool RagePhoto::load()
268298 return false ;
269299 compressedSize = charToUInt32LE (uInt32Buffer);
270300
271- char compressedPhoto[compressedSize];
301+ char *compressedPhoto = static_cast <char *>(malloc (compressedSize));
302+ if (!compressedPhoto)
303+ return false ;
272304 size = dataBuffer.read (compressedPhoto, compressedSize);
273- if (size != compressedSize)
305+ if (size != compressedSize) {
306+ free (compressedPhoto);
274307 return false ;
308+ }
275309 QByteArray t_photoData = QByteArray::fromRawData (compressedPhoto, compressedSize);
276310 p_photoData = qUncompress (t_photoData);
311+ free (compressedPhoto);
277312
278313 size = dataBuffer.read (uInt32Buffer, 4 );
279314 if (size != 4 )
@@ -290,12 +325,17 @@ bool RagePhoto::load()
290325 return false ;
291326 compressedSize = charToUInt32LE (uInt32Buffer);
292327
293- char compressedJson[compressedSize];
328+ char *compressedJson = static_cast <char *>(malloc (compressedSize));
329+ if (!compressedJson)
330+ return false ;
294331 size = dataBuffer.read (compressedJson, compressedSize);
295- if (size != compressedSize)
332+ if (size != compressedSize) {
333+ free (compressedJson);
296334 return false ;
335+ }
297336 QByteArray t_jsonBytes = QByteArray::fromRawData (compressedJson, compressedSize);
298337 p_jsonData = qUncompress (t_jsonBytes);
338+ free (compressedJson);
299339 if (p_jsonData.isEmpty ())
300340 return false ;
301341 QJsonDocument t_jsonDocument = QJsonDocument::fromJson (p_jsonData);
@@ -318,12 +358,17 @@ bool RagePhoto::load()
318358 return false ;
319359 compressedSize = charToUInt32LE (uInt32Buffer);
320360
321- char compressedTitl[compressedSize];
361+ char *compressedTitl = static_cast <char *>(malloc (compressedSize));
362+ if (!compressedTitl)
363+ return false ;
322364 size = dataBuffer.read (compressedTitl, compressedSize);
323- if (size != compressedSize)
365+ if (size != compressedSize) {
366+ free (compressedTitl);
324367 return false ;
368+ }
325369 QByteArray t_titlBytes = QByteArray::fromRawData (compressedTitl, compressedSize);
326370 t_titlBytes = qUncompress (t_titlBytes);
371+ free (compressedTitl);
327372 p_titleString = QString::fromUtf8 (t_titlBytes);
328373
329374 size = dataBuffer.read (uInt32Buffer, 4 );
@@ -341,12 +386,17 @@ bool RagePhoto::load()
341386 return false ;
342387 compressedSize = charToUInt32LE (uInt32Buffer);
343388
344- char compressedDesc[compressedSize];
389+ char *compressedDesc = static_cast <char *>(malloc (compressedSize));
390+ if (!compressedDesc)
391+ return false ;
345392 size = dataBuffer.read (compressedDesc, compressedSize);
346- if (size != compressedSize)
393+ if (size != compressedSize) {
394+ free (compressedDesc);
347395 return false ;
396+ }
348397 QByteArray t_descBytes = QByteArray::fromRawData (compressedDesc, compressedSize);
349398 t_descBytes = qUncompress (t_descBytes);
399+ free (compressedDesc);
350400 p_descriptionString = QString::fromUtf8 (t_descBytes);
351401
352402 size = dataBuffer.read (uInt32Buffer, 4 );
@@ -382,7 +432,7 @@ bool RagePhoto::load()
382432 size = dataBuffer.read (length, 1 );
383433 if (size != 1 )
384434 return false ;
385- int i_length = QByteArray::number (( int ) length[0 ], 16 ).toInt () + 6 ;
435+ int i_length = QByteArray::number (static_cast < int >( length[0 ]) , 16 ).toInt () + 6 ;
386436
387437#if QT_VERSION >= 0x050A00
388438 size = dataBuffer.skip (i_length);
0 commit comments