在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):amethyst/rlua开源软件地址(OpenSource Url):https://github.com/amethyst/rlua开源编程语言(OpenSource Language):C 53.1%开源软件介绍(OpenSource Introduction):rlua -- High level bindings between Rust and LuaThis library is a high level interface between Rust and Lua. Its goal is to be an easy to use, practical, flexible, and safe API between Rust and Lua.
API stabilityCurrently, this library follows a pre-1.0 semver, so all API changes should be accompanied by 0.x version bumps. See the Version 1.0 milestone for the work planned to be done before a more stable 1.0 release. There may be breaking changes as these issues are dealt with on the way (the version number will be bumped as needed). Lua versions supportedAs of release 0.18, the version of Lua can be configured at build time using Cargo features. Lua 5.4 is the default. The rlua API stays the same with different Lua versions, though there are a small number of limitations. Lua code may, of course, behave a little differently between the versions. Only one can be selected at a time, so to select anything other than the default (built-in Lua 5.4) you will need to disable default features. The available features are:
At current writing rlua has not been tested with alternative Lua implementations (such as Luajit) which share PUC-Rio Lua's C API, but it is expected that they can be made to work with little if any change to rlua, and support would be welcome. Other Lua featuresSome other features affect how Lua is built (for the builtin versions):
Safety and PanicsThe goal of this library is complete safety by default: it should not be
possible to cause undefined behavior with the safe API, even in edge cases.
Unsoundness is considered the most serious kind of bug, so if you find the
ability to cause UB with this API without This includes calling functions in the Lua standard library; some unsafe
functions are wrapped by default (for example to prevent loading binary
modules), but these wrappers can be disabled using one of the Another goal of this library is complete protection from panics: currently, it should not be possible for a script to trigger a panic. There ARE however several internal panics in the library, but triggering them is considered a bug. If you find a way to trigger these internal panics, please file a bug report. Yet another goal of the library is to, in all cases, safely handle panics that are generated inside Rust callbacks. Panic unwinds in Rust callbacks should currently be handled correctly -- the unwind is caught and carried across the Lua API boundary as a regular Lua error in a way that prevents Lua from catching it. This is done by overriding the normal Lua 'pcall' and 'xpcall' functions with custom versions that cannot catch errors that are actually from Rust panics, and by handling panic errors on the receiving Rust side by resuming the panic.
In summary, here is a list of
Sandboxing and Untrusted ScriptsThe API now contains the pieces necessary to implement simple, limited "sandboxing" of Lua scripts by controlling their environment, limiting their allotted VM instructions, and limiting the amount of memory they may allocate. These features deserve a few words of warning: Do not use them to run untrusted scripts unless you really Know What You Are Doing (tm) (and even then, you probably should not do this). First, this library contains a huge amount of unsafe code, and I currently would not trust it in a truly security sensitive context. There are almost certainly bugs still lurking in this library! It is surprisingly, fiendishly difficult to use the Lua C API without the potential for unsafety. Second, properly sandboxing Lua scripts can be quite difficult, much of the stdlib is unsafe, and sometimes in surprising ways. Some information on this can be found here. Third, PUC-Rio Lua is a C library not really designed to be used with untrusted scripts. Please understand that though PUC-Rio Lua is an extremely well written language runtime, it is still quite a lot of C code, and it is not commonly used with truly malicious scripts. Take a look here and count how many bugs resulted in memory unsafety in the interpreter. Another small example: did you know there is a way to attack Lua tables to cause linear complexity in the table length operator? That this still counts as one VM instruction? Fourth, if you provide a callback API to scripts, it can be very difficult to secure that API. Do all of your API functions have some maximum runtime? Do any of your API functions allow the script to allocate via Rust? Are there limits on how much they can allocate this way? All callback functions still count as a single VM instruction! In any case, sandboxing in this way may still be useful to protect against buggy (but non-malicious) scripts, and may even serve as a single layer of a larger security strategy, but please think twice before relying on this to protect you from untrusted Lua code. LicenseThis project is licensed under the MIT license |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论