Skip to content
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

Add sanity checks to all LCF data structure access #1259

Merged
merged 15 commits into from Jan 2, 2018

Conversation

Projects
None yet
3 participants
@Ghabry
Copy link
Member

Ghabry commented Sep 9, 2017

to reduce crashes and exploit surface.

*
* Data::items (but not skills of items!)
*
*/

This comment has been minimized.

@Ghabry

Ghabry Sep 9, 2017

Author Member

have to update this comment

int final_level = Data::actors[actor_id - 1].final_level;
exp_list.resize(final_level, 0);;
for (int i = 1; i < final_level; ++i) {
exp_list.resize(99);

This comment has been minimized.

@carstene1ns

carstene1ns Sep 9, 2017

Member

Magic number, maybe use GetMaxLevel().

This comment has been minimized.

@Ghabry

Ghabry Sep 19, 2017

Author Member

Yes, this looks safe because GetLevel() is sanitized.

}

int Game_Actor::SetEquipment(int equip_type, int new_item_id) {
if (equip_type <= 0 || equip_type > (int) GetData().equipped.size())
return -1;


This comment has been minimized.

@carstene1ns

carstene1ns Sep 9, 2017

Member

stray newline

@@ -583,7 +607,7 @@ int Game_Actor::GetLevel() const {
}

int Game_Actor::GetMaxLevel() const {
return Data::actors[actor_id - 1].final_level;
return std::max(1, std::min(GetActor().final_level, Player::IsRPG2k() ? 50 : 99));

This comment has been minimized.

@carstene1ns

carstene1ns Sep 9, 2017

Member

Magic numbers, maybe we should add max_actor_level_* constants.


float bottom = top;
if (terrain) {
bottom = top + terrain->grid_b;

This comment has been minimized.

@carstene1ns

carstene1ns Sep 9, 2017

Member

/ 13 is missing from old code.

const RPG::State& state = *ReaderUtil::GetElement(Data::states, i);

if (state.affect_agility) {
n = AffectParameter(state.affect_agility, base_agi);

This comment has been minimized.

@carstene1ns

carstene1ns Sep 9, 2017

Member

This was affect_type before, wrong?

@carstene1ns carstene1ns added this to the 0.5.3 milestone Sep 9, 2017

@Ghabry Ghabry force-pushed the Ghabry:sanitycheck branch from 041b5fb to f7ee1ef Sep 20, 2017

@Ghabry

This comment has been minimized.

Copy link
Member Author

Ghabry commented Sep 20, 2017

Fixed the reported problems and found more problems in the code.
Did a new commit to make the review easier.

@@ -102,6 +103,7 @@ void Window_BattleStatus::RefreshGauge() {
}

for (int i = 0; i < item_max; ++i) {
// The always only contains valid battlers

This comment has been minimized.

@carstene1ns

carstene1ns Sep 20, 2017

Member

who?

@carstene1ns

This comment has been minimized.

Copy link
Member

carstene1ns commented Sep 20, 2017

Looks good to me now apart from a few language issues in the comments, but this does not really matter.
e.g.
[…] array is resized dynamically


Not going to merge this, until at least a second review is available 😁.

@carstene1ns carstene1ns requested a review from fdelapena Sep 20, 2017

@Ghabry

This comment has been minimized.

Copy link
Member Author

Ghabry commented Sep 20, 2017

And that review should take at least 30 minutes ;)

@@ -18,6 +18,7 @@
// Headers
#include <algorithm>
#include <sstream>
#include <reader_util.h>

This comment has been minimized.

@fdelapena

fdelapena Sep 20, 2017

Contributor

Other places use quotes for liblcf includes. (2)

@@ -18,6 +18,7 @@
#include <algorithm>
#include <cassert>
#include <deque>
#include <reader_util.h>

This comment has been minimized.

@fdelapena

fdelapena Sep 20, 2017

Contributor

Other places use quotes for liblcf includes. (3)

@@ -25,6 +25,8 @@
#include "background.h"
#include "bitmap.h"
#include "main_data.h"
#include "reader_util.h"

This comment has been minimized.

@fdelapena

fdelapena Sep 20, 2017

Contributor

Other places use quotes for liblcf includes. (1)

This comment has been minimized.

@Ghabry

Ghabry Sep 23, 2017

Author Member

Fixed all your notes except this one because it already uses quotes

@@ -20,6 +20,7 @@
#include <cstdlib>
#include <algorithm>
#include <sstream>
#include <reader_util.h>

This comment has been minimized.

@fdelapena

fdelapena Sep 20, 2017

Contributor

Other places use quotes for liblcf includes. (4)

@@ -16,6 +16,7 @@
*/

// Headers
#include <reader_util.h>

This comment has been minimized.

@fdelapena

fdelapena Sep 20, 2017

Contributor

Other places use quotes for liblcf includes. (5)

@@ -16,11 +16,13 @@
*/

// Headers
#include <reader_util.h>

This comment has been minimized.

@fdelapena

fdelapena Sep 20, 2017

Contributor

Other places use quotes for liblcf includes. (27)

@@ -18,12 +18,18 @@
// Headers
#include <iomanip>
#include <sstream>
#include <reader_util.h>

This comment has been minimized.

@fdelapena

fdelapena Sep 20, 2017

Contributor

Other places use quotes for liblcf includes. (28)

@@ -18,6 +18,7 @@
// Headers
#include <iomanip>
#include <sstream>
#include <reader_util.h>

This comment has been minimized.

@fdelapena

fdelapena Sep 20, 2017

Contributor

Other places use quotes for liblcf includes. (29)

@@ -17,6 +17,7 @@

// Headers
#include <sstream>
#include <reader_util.h>

This comment has been minimized.

@fdelapena

fdelapena Sep 20, 2017

Contributor

Other places use quotes for liblcf includes. (30)

@@ -19,6 +19,7 @@
#include <algorithm>
#include <cassert>
#include <cmath>
#include <reader_util.h>

This comment has been minimized.

@fdelapena

fdelapena Sep 20, 2017

Contributor

Other places use quotes for liblcf includes. (31)

@Ghabry Ghabry force-pushed the Ghabry:sanitycheck branch from f7ee1ef to e8f04e7 Sep 23, 2017

@Ghabry Ghabry modified the milestones: 0.5.3, 0.5.4 Oct 1, 2017

@Ghabry Ghabry force-pushed the Ghabry:sanitycheck branch 3 times, most recently from e8f04e7 to e0bf97f Nov 4, 2017

@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017

@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017

@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017

@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017

@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017

@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017

@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017

@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017

@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017

@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017

@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017

@EasyRPG EasyRPG deleted a comment from JenkinsRPG Nov 4, 2017

@carstene1ns

This comment has been minimized.

Copy link
Member

carstene1ns commented Nov 26, 2017

Okay, did not know they were needed then.

@carstene1ns

This comment has been minimized.

Copy link
Member

carstene1ns commented Nov 26, 2017

There seems to be a problem when returning to the gamebrowser from some games (maybe data is not cleared or cleared in the wrong order?): Warning: Removing invalid item # from party

@Ghabry

This comment has been minimized.

Copy link
Member Author

Ghabry commented Nov 27, 2017

Can you telll me a game where thus can be reproduced?

@carstene1ns

This comment has been minimized.

Copy link
Member

carstene1ns commented Nov 27, 2017

Example games: Embric, Jojo, Lavender, Mondschein
To reproduce load a save or begin the game, press F12 and choose Exit in the Menu.

@Ghabry

This comment has been minimized.

Copy link
Member Author

Ghabry commented Nov 29, 2017

Had to add special handling for level 0 everywhere to prevent nullptr-dereferences due to new sanity checks (guess before it read out of bounds and somehow survived).

The last commit was a random find while testing Ara Fell.

@Ghabry Ghabry force-pushed the Ghabry:sanitycheck branch from a3ca50c to 7be4595 Dec 6, 2017

@Ghabry

This comment has been minimized.

Copy link
Member Author

Ghabry commented Dec 6, 2017

Sorry for the rebase, was to prevent a future conflict. Had to remove a sanity check in "SetupBattle" because the original code has a bug and can be completely deleted. Will open an issue for this. #1314

The last unreviewed commit was:
"Add exception in the sanity check and special handling for Level 0"

Battle system: Fix out-of-bounds read when a battle charset is used a…
…nd the idle and the action animation are the same.
@carstene1ns

This comment has been minimized.

Copy link
Member

carstene1ns commented Dec 30, 2017

Well, have further investigated the reason why the message pops up:
When returning from game to title scene via F12, Data is not cleared when Player::ResetGameObjects() is called. Thus, the items are still valid. However, when returning to the gamebrowser, they are still there, but Data::Clear() has been called, so they are invalid.

As a fix, i think clearing the party items is necessary when leaving the game, either in ResetGameObjects() or where the party members are removed.

Fix regression that prevented deletion of the items when a new game s…
…tarted (and generated sanity check warnings in the game browser)

Fix #1298 again

@carstene1ns carstene1ns merged commit 34a6b9d into EasyRPG:master Jan 2, 2018

7 checks passed

Android (armeabi-v7a) Build finished.
Details
GCW0 Build finished.
Details
GNU/Linux Build finished.
Details
OSX Build finished.
Details
Windows (x64) Build finished.
Details
Windows (x86) Build finished.
Details
web Build finished.
Details
@Ghabry

This comment has been minimized.

Copy link
Member Author

Ghabry commented Jan 2, 2018

Looking forward to the bug reports. ;)

@Ghabry Ghabry deleted the Ghabry:sanitycheck branch May 7, 2018

@Albeleon Albeleon referenced this pull request Jul 7, 2018

Open

Battle System: Remaining, not implemented stuff #821

34 of 35 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.