Skip to content

Commit a689c32

Browse files
authored
Merge branch 'develop' into uniformed-filter
2 parents 7daf2e7 + a39e8ab commit a689c32

17 files changed

Lines changed: 178 additions & 16 deletions

File tree

.github/workflows/build-windows.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ jobs:
6868
name: Build win64
6969
runs-on: windows-2022
7070
steps:
71+
- name: Set up Python
72+
uses: actions/setup-python@v6
73+
with:
74+
python-version: '3.x'
7175
- name: Install build dependencies
7276
run: |
7377
choco install sccache

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ repos:
2020
args: ['--fix=lf']
2121
- id: trailing-whitespace
2222
- repo: https://github.com/python-jsonschema/check-jsonschema
23-
rev: 0.36.0
23+
rev: 0.36.1
2424
hooks:
2525
- id: check-github-workflows
2626
- repo: https://github.com/Lucas-C/pre-commit-hooks
27-
rev: v1.5.5
27+
rev: v1.5.6
2828
hooks:
2929
- id: forbid-tabs
3030
exclude_types:

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cmake_policy(SET CMP0048 NEW)
66
cmake_policy(SET CMP0074 NEW)
77

88
# set up versioning.
9-
set(DF_VERSION "53.09")
9+
set(DF_VERSION "53.10")
1010
set(DFHACK_RELEASE "r1")
1111
set(DFHACK_PRERELEASE FALSE)
1212

docs/changelog.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ Template for new versions:
5858

5959
## New Features
6060
- `sort`: added ``Uniformed`` filter to squad assignment screen to filter dwarves with mining, woodcutting, or hunting labors
61+
- `sort`: Add death cause button to dead/missing tab in the creatures screen
6162

6263
## Fixes
6364

6465
## Misc Improvements
66+
- Core: DFHack now validates vtable pointers in objects read from memory and will throw an exception instead of crashing when an invalid vtable pointer is encountered. This makes it easier to identify which DF data structure contains corrupted data when this manifests in the form of a bad vtable pointer, and shifts blame for such crashes from DFHack to DF.
6567

6668
## Documentation
6769

@@ -71,6 +73,28 @@ Template for new versions:
7173

7274
## Removed
7375

76+
# 53.10-r1
77+
78+
## New Tools
79+
80+
## New Features
81+
82+
## Fixes
83+
- `autochop`: the report will no longer throw a C++ exception when burrows are defined.
84+
- `suspendmanager`: Fix the overlay appearing where it should not when following a unit
85+
86+
## Misc Improvements
87+
88+
## Documentation
89+
90+
## API
91+
- Added ``Burrows::getName``: obtains the name of a burrow, or the same placeholder name that DF would show if the burrow is unnamed.
92+
93+
## Lua
94+
- Added ``Burrows::getName`` as ``dfhack.burrows.getName``.
95+
96+
## Removed
97+
7498
# 53.09-r1
7599

76100
## New Tools

docs/dev/Lua API.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,6 +2489,11 @@ Maps module
24892489
Burrows module
24902490
--------------
24912491

2492+
* ``dfhack.burrows.getName(burrow)``
2493+
2494+
Returns the name of the burrow.
2495+
If the burrow has no set name, returns the same placeholder name that DF would show in the UI.
2496+
24922497
* ``dfhack.burrows.findByName(name[, ignore_final_plus])``
24932498

24942499
Returns the burrow pointer or *nil*. if ``ignore_final_plus`` is ``true``,

library/DataDefs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ const virtual_identity *virtual_identity::find(void *vtable)
370370

371371
// If using a reader/writer lock, re-grab as write here, and recheck
372372
Core &core = Core::getInstance();
373-
std::string name = core.p->doReadClassName(vtable);
373+
std::string name = core.p->readClassName(vtable);
374374

375375
auto name_it = (*name_lookup).find(name);
376376
if (name_it != (*name_lookup).end()) {

library/Process.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ Process::~Process()
236236

237237
string Process::doReadClassName (void * vptr)
238238
{
239+
if (!checkValidAddress(vptr))
240+
throw std::runtime_error(fmt::format("invalid vtable ptr {}", vptr));
241+
239242
char* rtti = Process::readPtr(((char*)vptr - sizeof(void*)));
240243
#ifndef WIN32
241244
char* typestring = Process::readPtr(rtti + sizeof(void*));
@@ -591,6 +594,20 @@ void Process::getMemRanges(vector<t_memrange>& ranges)
591594
}
592595
#endif
593596

597+
bool Process::checkValidAddress(void* ptr)
598+
{
599+
uintptr_t addr = reinterpret_cast<uintptr_t>(ptr);
600+
auto validate = [&] (t_memrange& r) {
601+
uintptr_t lo = reinterpret_cast<uintptr_t>(r.start);
602+
uintptr_t hi = reinterpret_cast<uintptr_t>(r.end);
603+
return addr >= lo && addr < hi;
604+
};
605+
std::vector<t_memrange> mr;
606+
getMemRanges(mr);
607+
bool valid = std::any_of(mr.begin(), mr.end(), validate);
608+
return valid;
609+
}
610+
594611
uintptr_t Process::getBase()
595612
{
596613
#if WIN32

library/include/MemAccess.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ namespace DFHack
221221

222222
std::string readClassName(void* vptr)
223223
{
224-
std::map<void*, std::string>::iterator it = classNameCache.find(vptr);
224+
auto it = classNameCache.find(vptr);
225225
if (it != classNameCache.end())
226226
return it->second;
227227
return classNameCache[vptr] = doReadClassName(vptr);
@@ -247,6 +247,9 @@ namespace DFHack
247247
/// get virtual memory ranges of the process (what is mapped where)
248248
static void getMemRanges(std::vector<t_memrange>& ranges);
249249

250+
/// check if an address has a mapping
251+
bool checkValidAddress(void* ptr);
252+
250253
/// get the symbol table extension of this process
251254
std::shared_ptr<DFHack::VersionInfo> getDescriptor()
252255
{

library/include/modules/Burrows.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ namespace DFHack
4545
{
4646
namespace Burrows
4747
{
48+
DFHACK_EXPORT std::string getName(df::burrow* burrow);
49+
4850
DFHACK_EXPORT df::burrow *findByName(std::string name, bool ignore_final_plus = false);
4951

5052
// Units

library/modules/Burrows.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ using namespace df::enums;
5252
using df::global::world;
5353
using df::global::plotinfo;
5454

55+
std::string Burrows::getName(df::burrow* burrow)
56+
{
57+
CHECK_NULL_POINTER(burrow);
58+
return burrow->name.empty() ? fmt::format("Burrow {}", burrow->id + 1) : burrow->name;
59+
}
60+
61+
5562
df::burrow *Burrows::findByName(std::string name, bool ignore_final_plus)
5663
{
5764
auto &vec = df::burrow::get_vector();

0 commit comments

Comments
 (0)