-
Notifications
You must be signed in to change notification settings - Fork 607
Blockmap Size Error Checking (Fixes bug #1287) < 8000 span class="f1-light color-fg-muted">#1289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
1ec7a37
3d7b292
b327032
4703e60
ca54eb5
c802824
03aec42
31aab80
ea59b6c
7ef3f6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -531,6 +531,10 @@ void P_LoadBlockMap (int lump) | |
|
||
lumplen = W_LumpLength(lump); | ||
count = lumplen / 2; | ||
if(count >= 32766) | ||
{ | ||
I_Error("Blockmap too large"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a good error message. A better error message would include the two values that were compared and a link to the doomwiki.org page about the static limit. |
||
} | ||
|
||
blockmaplump = Z_Malloc(lumplen, PU_LEVEL, NULL); | ||
W_ReadLump(lump, blockmaplump); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -510,6 +510,10 @@ void P_LoadBlockMap (int lump) | |
|
||
lumplen = W_LumpLength(lump); | ||
count = lumplen / 2; | ||
if(count >= 32766) | ||
{ | ||
I_Error("Blockmap too large"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Respect the code style. For example, put a space between Code style: https://github.com/chocolate-doom/chocolate-doom/blob/master/HACKING.md There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
|
||
blockmaplump = Z_Malloc(lumplen, PU_LEVEL, NULL); | ||
W_ReadLump(lump, blockmaplump); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why exactly this number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the blockmap limit for doom / 2 (count = blockmap size / 2, and blockmap limit is 65536 in doom, so I put that /2 and checked it against count.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10000 form>Source: https://doomwiki.org/wiki/Blockmap#Compression
and C data type size for short (which is what blockmap is) is 65536
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, but this was a rhetorical question. 😉 I'd prefer if magic numbers in source code didn't "fall from the sky". Something like
USHRT_MAX/2
and an accompanying comment would probably be more meaningful.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, 32766 is the wrong number since 65536 / 2 = 32768. A good example of why Fabian's approach is the better one.