diff options
| author | Gangzheng Tong <tonggangzheng@gmail.com> | 2025-05-16 20:59:55 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-17 03:59:55 +0000 |
| commit | 49667272add1963c6937a63898de6881b2e455aa (patch) | |
| tree | a51b22e1a53ca969fc6797a0875cc7c5a6456861 /examples/gpu-printing/gpu-printing.cpp | |
| parent | d58243d9041947c99f18b82385e62c082507decb (diff) | |
fix the break to make sure only valid data will be accessed (#7148)
Diffstat (limited to 'examples/gpu-printing/gpu-printing.cpp')
| -rw-r--r-- | examples/gpu-printing/gpu-printing.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/examples/gpu-printing/gpu-printing.cpp b/examples/gpu-printing/gpu-printing.cpp index f71578554..a0d5e5919 100644 --- a/examples/gpu-printing/gpu-printing.cpp +++ b/examples/gpu-printing/gpu-printing.cpp @@ -140,8 +140,16 @@ void GPUPrinting::processGPUPrintCommands(const void* data, size_t dataSize) // avoid crashes from a command trying to fetch data past // the end of the buffer. // - if (payloadWordCount > size_t(dataCursor - dataEnd)) + ptrdiff_t wordsAvailable = dataEnd - dataCursor; + if (wordsAvailable < 0 || payloadWordCount > (uint32_t)wordsAvailable) { + fprintf( + stderr, + "error: GPU printing buffer corruption or insufficient data for payload.\n" + " Op: %d, Declared Payload Words: %u, Available Words: %td\n", + (int)op, + payloadWordCount, + (wordsAvailable < 0 ? 0 : wordsAvailable)); break; } // |
