| 207 | /************************************************************************/ |
| 208 | |
| 209 | GByte *GDALJP2Box::ReadBoxData() |
| 210 | |
| 211 | { |
| 212 | GIntBig nDataLength = GetDataLength(); |
| 213 | if (nDataLength > 100 * 1024 * 1024) |
| 214 | { |
| 215 | CPLError(CE_Failure, CPLE_AppDefined, |
| 216 | "Too big box : " CPL_FRMT_GIB " bytes", nDataLength); |
| 217 | return nullptr; |
| 218 | } |
| 219 | |
| 220 | if (VSIFSeekL(fpVSIL, static_cast<vsi_l_offset>(nDataOffset), SEEK_SET) != |
| 221 | 0) |
| 222 | return nullptr; |
| 223 | |
| 224 | char *pszData = static_cast<char *>( |
| 225 | VSI_MALLOC_VERBOSE(static_cast<int>(nDataLength) + 1)); |
| 226 | if (pszData == nullptr) |
| 227 | return nullptr; |
| 228 | |
| 229 | if (static_cast<GIntBig>(VSIFReadL( |
| 230 | pszData, 1, static_cast<int>(nDataLength), fpVSIL)) != nDataLength) |
| 231 | { |
| 232 | CPLError(CE_Failure, CPLE_AppDefined, "Cannot read box content"); |
| 233 | CPLFree(pszData); |
| 234 | return nullptr; |
| 235 | } |
| 236 | |
| 237 | pszData[nDataLength] = '\0'; |
| 238 | |
| 239 | return reinterpret_cast<GByte *>(pszData); |
| 240 | } |
| 241 | |
| 242 | /************************************************************************/ |
| 243 | /* GetDataLength() */ |
no test coverage detected