| 332 | } |
| 333 | |
| 334 | void Buffer::configure(const BufferParams& params) { |
| 335 | // Validate buffer span |
| 336 | if (params.buffer.data() == nullptr || params.buffer.empty()) { |
| 337 | std::cerr << "[Error] Buffer span is null or empty" << std::endl; |
| 338 | return; |
| 339 | } |
| 340 | |
| 341 | // Validate dimensions |
| 342 | if (!validate_dimension(params.buffer_width_i, |
| 343 | "width", |
| 344 | BufferConstants::MIN_BUFFER_DIMENSION, |
| 345 | BufferConstants::MAX_BUFFER_DIMENSION)) { |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | if (!validate_dimension(params.buffer_height_i, |
| 350 | "height", |
| 351 | BufferConstants::MIN_BUFFER_DIMENSION, |
| 352 | BufferConstants::MAX_BUFFER_DIMENSION)) { |
| 353 | return; |
| 354 | } |
| 355 | |
| 356 | // Validate channel count |
| 357 | if (params.channels < BufferConstants::MIN_CHANNELS || |
| 358 | params.channels > BufferConstants::MAX_CHANNELS) { |
| 359 | std::cerr << "[Error] Invalid channel count: " << params.channels |
| 360 | << " (must be between " << BufferConstants::MIN_CHANNELS |
| 361 | << " and " << BufferConstants::MAX_CHANNELS << ")" |
| 362 | << std::endl; |
| 363 | return; |
| 364 | } |
| 365 | |
| 366 | // Validate step (must be positive and at least as large as channels) |
| 367 | if (params.step < params.channels) { |
| 368 | std::cerr << "[Error] Invalid step: " << params.step |
| 369 | << " (must be >= channels: " << params.channels << ")" |
| 370 | << std::endl; |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | // Validate buffer size (prevent potential DoS). The real memory footprint |
| 375 | // is the size of the received pixel data. `step` is in pixels per row (see |
| 376 | // GL_UNPACK_ROW_LENGTH below), so a width*height*step estimate would |
| 377 | // double-count the row width and reject valid large buffers. Validate the |
| 378 | // actual byte count against the same 16 GB ceiling the desktop build uses. |
| 379 | // Cast to uint64 so the comparison is well-formed on 32-bit builds, where |
| 380 | // size_t cannot represent the 16 GB ceiling (this ceiling only ever binds |
| 381 | // on the 64-bit desktop build). |
| 382 | if (const auto buffer_size = |
| 383 | static_cast<std::uint64_t>(params.buffer.size()); |
| 384 | buffer_size > BufferConstants::MAX_BUFFER_SIZE) { |
| 385 | std::cerr << "[Error] Buffer size too large: " << buffer_size |
| 386 | << " bytes (maximum: " << BufferConstants::MAX_BUFFER_SIZE |
| 387 | << " bytes)" << std::endl; |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | buffer_ = params.buffer; |
no test coverage detected