CelestiaProject / Celestia

Real-time 3D visualization of space.
https://celestiaproject.space
GNU General Public License v2.0
1.86k stars 309 forks source link

Enforce an upper limit on image size #2249

Closed ajtribick closed 2 weeks ago

ajtribick commented 3 weeks ago

It would probably make sense to impose a check on image sizes at load time to avoid trying to deal with huge images (or corrupt files whose metadata claims that the image dimensions are absurdly large). Any suggestions for an upper limit, e.g. maximum dimension 8192, 16384, 32768?

(For virtual textures this would be a per-tile limit)

375gnu commented 3 weeks ago

At least they should not be larger then max texture size.

ajtribick commented 3 weeks ago

As an initial step, I think 16384 makes sense as an initial hard limit, since it's the largest power-of-two where the byte size of an 8-bit per channel RGBA image does not overflow a 32-bit signed integer (relevant for, e.g. ptrdiff_t on 32-bit systems).

375gnu commented 3 weeks ago
std::min(16384, gl::maxTextureSize);
ajtribick commented 2 weeks ago

Looks like we already implement splitting images into tiles when loading them as textures: https://github.com/CelestiaProject/Celestia/blob/97fe2c9c101d4ccba887fb9cd8d6a3de90b11344/src/celengine/texture.cpp#L352-L377

So I think we can implement the hard limit in the image loader and rely on the texture loader to implement the OpenGL-specific requirements.