Skip to content

Commit ef1bd5d

Browse files
authored
Added guard for 32-bit overflow in spritefont reading (#627)
1 parent 3514f3f commit ef1bd5d

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

.github/copilot-instructions.md

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

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

2020
## General Guidelines
2121

22-
- **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/DirectXTK/wiki/Implementation). The library implementation is written to be compatible with C++14 features, but C++17 is required to build the project for the command-line tools which utilize C++17 filesystem for long file path support.
22+
- **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/DirectXTK/wiki/Implementation). The library's public API requires C++11, and the project builds with C++17 (`CMAKE_CXX_STANDARD 17`). The command-line tools also use C++17, including `<filesystem>` for long file path support. This code is designed to build with Visual Studio 2022, Visual Studio 2026, clang for Windows v12 or later, or MinGW 12.2.
2323
> 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`.
2424
- **Documentation**: The project provides documentation in the form of wiki pages available at [Documentation](https://github.com/microsoft/DirectXTK/wiki/).
2525
- **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.
@@ -35,13 +35,13 @@ These instructions define how GitHub Copilot should assist with this project. Th
3535
.azuredevops/ # Azure DevOps pipeline configuration and policy files.
3636
.github/ # GitHub Actions workflow files and linter configuration files.
3737
.nuget/ # NuGet package configuration files.
38-
build/ # Miscellaneous build files and scripts.
38+
build/ # Miscellaneous build files and scripts, including OneFuzzConfig.json.
3939
Audio/ # DirectX Tool Kit for Audio implementation files.
4040
Inc/ # Public header files.
4141
Src/ # Implementation header and source files.
4242
Shaders/ # HLSL shader files.
43-
MakeSpriteFont/ # CLI tool for capturing sprite fonts.
44-
XWBTool/ # CLI tool for creating XACT-style wave banks.
43+
MakeSpriteFont/ # C# CLI tool for capturing sprite fonts.
44+
XWBTool/ # C++ CLI tool for creating XACT-style wave banks.
4545
Tests/ # Tests are designed to be cloned from a separate repository at this location.
4646
wiki/ # Local clone of the GitHub wiki documentation repository.
4747
```
@@ -63,6 +63,10 @@ wiki/ # Local clone of the GitHub wiki documentation repository.
6363
- All implementation `.cpp` files include `pch.h` as their first include (precompiled header). MinGW builds skip precompiled headers.
6464
- `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`.
6565

66+
#### Inline Namespace
67+
68+
All public headers that contain types shared with the DirectX 12 version of the *DirectX Tool Kit* use `inline namespace DX11` inside `namespace DirectX`. This provides link-unique names (e.g. `DirectX::DX11::SpriteBatch`) without requiring explicit `DX11` qualification in client code. When adding new public types that also exist in DirectXTK12, place them inside this inline namespace.
69+
6670
#### SAL Annotations
6771

6872
All public API functions must use SAL annotations on every parameter. Use `_Use_decl_annotations_` at the top of each implementation that has SAL in the header declaration — never repeat the annotations in the `.cpp` or `.inl` file.
@@ -231,8 +235,10 @@ When creating documentation:
231235

232236
## Cross-platform Support Notes
233237

234-
- The code supports building for Windows.
238+
- The code targets Win32 desktop applications for Windows 8.1 or later, Xbox One, Xbox Series X|S, and Universal Windows Platform (UWP) apps for Windows 10 and Windows 11.
235239
- Portability and conformance of the code is validated by building with Visual C++, clang/LLVM for Windows, and MinGW.
240+
- For Xbox development, the project provides MSBuild solutions for GDK (`DirectXTK_GDK_2022.sln`) and GDK with Xbox Extensions (`DirectXTK_GDKW_2022.sln`). The CMake build supports Xbox via the `XBOX_CONSOLE_TARGET` variable (`scarlett` or `xboxone`).
241+
- The project ships MSBuild projects for Visual Studio 2022 (`.sln` / `.vcxproj`) and Visual Studio 2026 (`.slnx` / `.vcxproj`). VS 2019 projects have been retired.
236242

237243
### Platform and Compiler `#ifdef` Guards
238244

@@ -241,14 +247,20 @@ Use these established guards — do not invent new ones:
241247
| Guard | Purpose |
242248
| --- | --- |
243249
| `_WIN32` | Windows platform (desktop, UWP, Xbox) |
244-
| `_GAMING_XBOX` | Xbox One |
250+
| `_GAMING_XBOX` | Xbox platform (GDK — covers both Xbox One and Xbox Series X\|S) |
251+
| `_GAMING_XBOX_SCARLETT` | Xbox Series X\|S (GDK with Xbox Extensions) |
252+
| `_GAMING_XBOX_XBOXONE` | Xbox One (GDK with Xbox Extensions) |
245253
| `_XBOX_ONE && _TITLE` | Xbox One XDK (legacy) |
246254
| `_MSC_VER` | MSVC-specific (and MSVC-like clang-cl) pragmas and warning suppression |
247255
| `__clang__` | Clang/LLVM diagnostic suppressions |
248256
| `__GNUC__` | MinGW/GCC DLL attribute equivalents |
249257
| `_M_ARM64` / `_M_X64` / `_M_IX86` | Architecture-specific code paths for MSVC (`#ifdef`) |
250258
| `_M_ARM64EC` | ARM64EC ABI (ARM64 code with x64 interop) for MSVC |
251259
| `__aarch64__` / `__x86_64__` / `__i386__` | Additional architecture-specific symbols for MinGW/GNUC (`#if`) |
260+
| `USING_GAMEINPUT` | GameInput API for GamePad, Keyboard, Mouse |
261+
| `USING_WINDOWS_GAMING_INPUT` | Windows.Gaming.Input API for GamePad |
262+
| `USING_XINPUT` | XInput API for GamePad, Keyboard, Mouse |
263+
| `USING_COREWINDOW` | CoreWindow-based input (UWP) for Keyboard, Mouse |
252264

253265
> `_M_ARM`/ `__arm__` is legacy 32-bit ARM which is deprecated.
254266

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)