Skip to content

Commit c037a02

Browse files
authored
Added guard for 32-bit overflow in spritefont reading (#399)
1 parent 8f5e7d6 commit c037a02

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

.github/copilot-instructions.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ These instructions define how GitHub Copilot should assist with this project. Th
1414

1515
- See the tutorial at [Getting Started](https://github.com/microsoft/DirectXTK12/wiki/Getting-Started).
1616
- The recommended way to integrate *DirectX Tool Kit for DirectX 12* into your project is by using the *vcpkg* Package Manager. See [d3d12game_vcpkg](https://github.com/walbourn/directx-vs-templates/tree/main/d3d12game_vcpkg) for a template which uses VCPKG.
17-
- You can make use of the nuget.org packages **directxtk12_desktop_2019**, **directxtk12_desktop_win10**, or **directxtk12_uwp**.
17+
- You can make use of the nuget.org packages **directxtk12_desktop_win10** or **directxtk12_uwp**.
1818
- You can also use the library source code directly in your project or as a git submodule.
1919

2020
> If you are new to DirectX, you may want to start with [DirectX Tool Kit for DirectX 11](https://github.com/microsoft/DirectXTK/wiki/Getting-Started) to learn many important concepts for Direct3D programming, HLSL shaders, and the code patterns used in this project with a more 'noobie friendly' API.
2121
2222
## General Guidelines
2323

24-
- **Code Style**: The project uses an .editorconfig file to enforce coding standards. Follow the rules defined in `.editorconfig` for indentation, line endings, and other formatting. Additional information can be found on the wiki at [Implementation](https://github.com/microsoft/DirectXTK12/wiki/Implementation). The library implementation is written to be compatible with C++14 features.
24+
- **Code Style**: The project uses an .editorconfig file to enforce coding standards. Follow the rules defined in `.editorconfig` for indentation, line endings, and other formatting. Additional information can be found on the wiki at [Implementation](https://github.com/microsoft/DirectXTK12/wiki/Implementation). The library's public API requires C++11, and the project builds with C++17 (`CMAKE_CXX_STANDARD 17`).F
2525
> Notable `.editorconfig` rules: C/C++ files use 4-space indentation, `crlf` line endings, and `latin1` charset — avoid non-ASCII characters in source files. HLSL files have separate indent/spacing rules defined in `.editorconfig`.
2626
- **Documentation**: The project provides documentation in the form of wiki pages available at [Documentation](https://github.com/microsoft/DirectXTK12/wiki/). The audio, input, and math implementations are identical to the DirectX Tool Kit for DirectX 11.
2727
- **Error Handling**: Use C++ exceptions for error handling and uses RAII smart pointers to ensure resources are properly managed. For some functions that return HRESULT error codes, they are marked `noexcept`, use `std::nothrow` for memory allocation, and should not throw exceptions.
2828
- **Testing**: Unit tests for this project are implemented in this repository [Test Suite](https://github.com/walbourn/directxtk12test/) and can be run using CTest per the instructions at [Test Documentation](https://github.com/walbourn/directxtk12test/wiki).
2929
- **Security**: This project uses secure coding practices from the Microsoft Secure Coding Guidelines, and is subject to the `SECURITY.md` file in the root of the repository. Functions that read input from image file, geometry files, and audio files are subject to OneFuzz fuzz testing to ensure they are secure against malformed files.
30-
- **Dependencies**: The project uses CMake and VCPKG for managing dependencies, making optional use of DirectXMath, DirectX-Headers, DirectX 12 Agility SDK, GameInput, and XAudio2Redist. The project can be built without these dependencies, relying on the Windows SDK for core functionality.
30+
- **Dependencies**: The project uses CMake and VCPKG for managing dependencies, making optional use of DirectXMath, DirectX-Headers, DirectX 12 Agility SDK, GameInput, and XAudio2Redist. The project can be built without these dependencies, relying on the Windows SDK for core functionality. Additional CMake build options include `BUILD_WGI` and `BUILD_XINPUT` for alternative input backends, `BUILD_MIXED_DX11` for DX11 toolkit interop, `ENABLE_SPECTRE_MITIGATION`, `ENABLE_CODE_ANALYSIS`, and `BUILD_FUZZING`.
3131
- **Continuous Integration**: This project implements GitHub Actions for continuous integration, ensuring that all code changes are tested and validated before merging. This includes building the project for a number of configurations and toolsets, running a subset of unit tests, and static code analysis including GitHub super-linter, CodeQL, and MSVC Code Analysis.
3232
- **Code of Conduct**: The project adheres to the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). All contributors are expected to follow this code of conduct in all interactions related to the project.
3333

@@ -64,6 +64,7 @@ wiki/ # Local clone of the GitHub wiki documentation repository.
6464
- Use 16-byte alignment (`_aligned_malloc` / `_aligned_free`) to support SIMD operations in the implementation, but do not expose this requirement in public APIs.
6565
- All implementation `.cpp` files include `pch.h` as their first include (precompiled header). MinGW builds skip precompiled headers.
6666
- `Model` and related classes require RTTI (`/GR` on MSVC, `__GXX_RTTI` on GCC/Clang). The CMake build enables `/GR` automatically; do not disable RTTI when using `Model`.
67+
- Many public headers use `inline namespace DX12` inside `namespace DirectX` to disambiguate from *DirectX Tool Kit for DirectX 11* types when both libraries are used together.
6768

6869
#### SAL Annotations
6970

@@ -86,7 +87,7 @@ Common annotations:
8687
Example:
8788

8889
```cpp
89-
// Header (BuffersHelpers.h)
90+
// Header (BufferHelpers.h)
9091
DIRECTX_TOOLKIT_API
9192
HRESULT __cdecl CreateStaticBuffer(
9293
_In_ ID3D12Device* device,
@@ -241,6 +242,7 @@ When creating documentation:
241242

242243
- The code supports building for Windows.
243244
- Portability and conformance of the code is validated by building with Visual C++, clang/LLVM for Windows, and MinGW.
245+
- The project ships MSBuild projects for Visual Studio 2022 (`.sln` / `.vcxproj`) and Visual Studio 2026 (`.slnx` / `.vcxproj`). VS 2019 projects have been retired.
244246

245247
### Platform and Compiler `#ifdef` Guards
246248

@@ -260,6 +262,11 @@ Use these established guards — do not invent new ones:
260262
| `_M_ARM64EC` | ARM64EC ABI (ARM64 code with x64 interop) for MSVC |
261263
| `__aarch64__` / `__x86_64__` / `__i386__` | Additional architecture-specific symbols for MinGW/GNUC (`#if`) |
262264
| `USING_DIRECTX_HEADERS` | External DirectX-Headers package in use |
265+
| `USING_GAMEINPUT` | GameInput API for GamePad, Keyboard, Mouse |
266+
| `USING_WINDOWS_GAMING_INPUT` | Windows.Gaming.Input API for GamePad |
267+
| `USING_XINPUT` | XInput API for GamePad, Keyboard, Mouse |
268+
| `USING_COREWINDOW` | CoreWindow-based input (UWP) for Keyboard, Mouse |
269+
| `USING_PIX_CUSTOM_MEMORY_EVENTS` | PIX custom memory event integration in GraphicsMemory |
263270

264271
> `_M_ARM`/ `__arm__` is legacy 32-bit ARM which is deprecated.
265272

Src/BinaryReader.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ namespace DirectX
4545
{
4646
static_assert(std::is_standard_layout<T>::value, "Can only read plain-old-data types");
4747

48-
uint8_t const* newPos = mPos + sizeof(T) * elementCount;
48+
uint64_t byteCount = uint64_t(sizeof(T)) * uint64_t(elementCount);
49+
if (byteCount > UINT32_MAX)
50+
throw std::overflow_error("ReadArray");
51+
52+
uint8_t const* newPos = mPos + static_cast<size_t>(byteCount);
4953

5054
if (newPos < mPos)
5155
throw std::overflow_error("ReadArray");

0 commit comments

Comments
 (0)