mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-29 16:18:01 +01:00
[MIRROR] Prevents NAN amounts infecting the chemistry reagent container system [MDB IGNORE] (#15482)
* Prevents NAN amounts infecting the chemistry reagent container system (#69017) * Don't allow NAN into the reagent holders, and better reporting on add reagent and remove reagent * Replace admin message with stack_trace and return and improve math defines to check for finite numbers * Refactor things to use these new defines, attempts to fix unit tests by filtering out <= 0 amounts first Co-authored-by: Aleksej Komarov <stylemistake@ gmail.com> * Prevents NAN amounts infecting the chemistry reagent container system Co-authored-by: oranges <email@oranges.net.nz> Co-authored-by: Aleksej Komarov <stylemistake@ gmail.com>
This commit is contained in:
co-authored by
Aleksej Komarov
oranges
parent
7a839dc37f
commit
8b2badefef
+10
-4
@@ -1,7 +1,13 @@
|
||||
// Remove these once we have Byond implementation.
|
||||
#define ISNAN(a) (a!=a)
|
||||
#define ISINF(a) (!ISNAN(a) && ISNAN(a-a))
|
||||
#define IS_INF_OR_NAN(a) (ISNAN(a-a))
|
||||
// ------------------------------------
|
||||
#define IS_NAN(a) (a!=a)
|
||||
|
||||
#define IS_INF__UNSAFE(a) (a==a && a-a!=a-a)
|
||||
#define IS_INF(a) (isnum(a) && IS_INF__UNSAFE(a))
|
||||
|
||||
#define IS_FINITE__UNSAFE(a) (a-a==a-a)
|
||||
#define IS_FINITE(a) (isnum(a) && IS_FINITE__UNSAFE(a))
|
||||
// ------------------------------------
|
||||
// Aight dont remove the rest
|
||||
|
||||
// Credits to Nickr5 for the useful procs I've taken from his library resource.
|
||||
@@ -104,7 +110,7 @@
|
||||
. = list()
|
||||
var/d = b*b - 4 * a * c
|
||||
var/bottom = 2 * a
|
||||
if(d < 0 || IS_INF_OR_NAN(d) || IS_INF_OR_NAN(bottom))
|
||||
if(d < 0 || !IS_FINITE__UNSAFE(d) || !IS_FINITE__UNSAFE(bottom))
|
||||
return
|
||||
var/root = sqrt(d)
|
||||
. += (-b + root) / bottom
|
||||
|
||||
@@ -174,8 +174,8 @@
|
||||
return
|
||||
|
||||
var/multiplier = text2num(params["multiplier"])
|
||||
if(!multiplier)
|
||||
to_chat(usr, span_alert("[src] only accepts a numerical multiplier!"))
|
||||
if(!multiplier || !IS_FINITE(multiplier))
|
||||
stack_trace("Invalid multiplier value in stack creation [multiplier], [usr] is likely attempting an exploit")
|
||||
return
|
||||
var/is_stack = ispath(being_built.build_path, /obj/item/stack)
|
||||
multiplier = clamp(round(multiplier),1,50)
|
||||
|
||||
@@ -357,7 +357,8 @@
|
||||
return
|
||||
if(!is_valid_recipe(recipe, recipes)) //href exploit protection
|
||||
return
|
||||
if(!multiplier || multiplier < 1) //href exploit protection
|
||||
if(!multiplier || multiplier < 1 || !IS_FINITE(multiplier)) //href exploit protection
|
||||
stack_trace("Invalid multiplier value in stack creation [multiplier], [usr] is likely attempting an exploit")
|
||||
return
|
||||
if(!building_checks(builder, recipe, multiplier))
|
||||
return
|
||||
|
||||
@@ -659,7 +659,7 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache())
|
||||
/// Do mind that the numbers can get very big and might hit BYOND's single point float limit.
|
||||
/datum/gas_mixture/proc/gas_pressure_quadratic(a, b, c, lower_limit, upper_limit)
|
||||
var/solution
|
||||
if(!IS_INF_OR_NAN(a) && !IS_INF_OR_NAN(b) && !IS_INF_OR_NAN(c))
|
||||
if(IS_FINITE(a) && IS_FINITE(b) && IS_FINITE(c))
|
||||
solution = max(SolveQuadratic(a, b, c))
|
||||
if(solution > lower_limit && solution < upper_limit) //SolveQuadratic can return empty lists so be careful here
|
||||
return solution
|
||||
@@ -670,7 +670,7 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache())
|
||||
/// We use the slope of an approximate value to get closer to the root of a given equation.
|
||||
/datum/gas_mixture/proc/gas_pressure_approximate(a, b, c, lower_limit, upper_limit)
|
||||
var/solution
|
||||
if(!IS_INF_OR_NAN(a) && !IS_INF_OR_NAN(b) && !IS_INF_OR_NAN(c))
|
||||
if(IS_FINITE(a) && IS_FINITE(b) && IS_FINITE(c))
|
||||
// We start at the extrema of the equation, added by a number.
|
||||
// This way we will hopefully always converge on the positive root, while starting at a reasonable number.
|
||||
solution = (-b / (2 * a)) + 200
|
||||
|
||||
@@ -163,10 +163,12 @@
|
||||
* * ignore splitting - Don't call the process that handles reagent spliting in a mob (impure/inverse) - generally leave this false unless you care about REAGENTS_DONOTSPLIT flags (see reagent defines)
|
||||
*/
|
||||
/datum/reagents/proc/add_reagent(reagent, amount, list/data=null, reagtemp = DEFAULT_REAGENT_TEMPERATURE, added_purity = null, added_ph, no_react = FALSE, override_base_ph = FALSE, ignore_splitting = FALSE)
|
||||
if(!isnum(amount) || !amount)
|
||||
// Prevents small amount problems, as well as zero and below zero amounts.
|
||||
if(amount <= CHEMICAL_QUANTISATION_LEVEL)
|
||||
return FALSE
|
||||
|
||||
if(amount <= CHEMICAL_QUANTISATION_LEVEL)//To prevent small amount problems.
|
||||
if(!IS_FINITE(amount))
|
||||
stack_trace("non finite amount passed to add reagent [amount] [reagent]")
|
||||
return FALSE
|
||||
|
||||
if(SEND_SIGNAL(src, COMSIG_REAGENTS_PRE_ADD_REAGENT, reagent, amount, reagtemp, data, no_react) & COMPONENT_CANCEL_REAGENT_ADD)
|
||||
@@ -277,13 +279,11 @@
|
||||
/// Remove a specific reagent
|
||||
/datum/reagents/proc/remove_reagent(reagent, amount, safety = TRUE, no_react = FALSE)//Added a safety check for the trans_id_to
|
||||
if(isnull(amount))
|
||||
amount = 0
|
||||
CRASH("null amount passed to reagent code")
|
||||
|
||||
if(!isnum(amount))
|
||||
stack_trace("null amount passed to reagent code")
|
||||
return FALSE
|
||||
|
||||
if(amount < 0)
|
||||
if(amount < 0 || !IS_FINITE(amount))
|
||||
stack_trace("invalid number passed to remove_reagent [amount]")
|
||||
return FALSE
|
||||
|
||||
var/list/cached_reagents = reagent_list
|
||||
|
||||
Reference in New Issue
Block a user