Skip to content

Some functions "pretend" to be "safe" while being unsafe #479

@phobos2077

Description

@phobos2077
  • get/set_proto_data - uses byte-offsets and has no range checking. Suggestion:

    • Don't accept offset < 0.
    • Check proto type/subtype and don't accept offsets above the upper bounds.
  • get/set_object_data - uses byte offsets and direct memory pointer for object, is not limited an any way. Available with UnsafeScripting disabled, but actually works exactly the same as read_xxx, write_xxx opcodes if you just pass 0 as object pointer...

    • Disable this function if UnsafeScripting is disabled, because it's impossible to know what type of object is being pointed to for proper offset range validation.
    • Mark as deprecated and remove from sfall.h. Who wants unsafe scripts should use normal unsafe scripting functions (just add object pointer and offsets together, duh).
    • Possibly add object-specific metarules with enum-based fields, just like get_ai_object_data or set_drugs_data.

This will break a few mods, but it is worth it, IMO:

  • Unsafe functions like these won't work when porting to Fallout CE or similar, unless they never actually go out of object bounds and the other engine has perfect struct binary compatibility with original game.
  • Just why have UnsafeScripting option in the first place if it doesn't actually disable unsafe scripting?

Of course if we want to somehow "protect" from malicious scripting, a lot of other things need to be considered (and not sure if it's really possible, given the game's engine is full of holes as it is). But I think we should at least discourage mod creators from using these not because of malicious intent, but simple errors in scripts that could lead to hard-to-debug crashes due to memory overwrites and reads at incorrect offsets.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions