| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
| |
affect other instances.
|
| |
|
|
| |
json_cfg_encode_indent stored the raw luaL_checkstring pointer, which aliases a Lua string that can be garbage-collected, causing a use-after-free / heap info-leak on a later encode(). Store a malloc'd copy, freed on reset and in __gc.
|
| |
|
|
| |
reslove two warnings and update the doc.
|
| | |
|
| | |
|
| |
|
|
|
|
|
|
|
|
|
|
| |
json_next_number_token stores the `long long` return value from `stroll`
in a `lua_Integer` (which is typically a typedef for `ptrdiff_t`).
On 32-bit platforms, this ends up storing an 8-byte number into a 4-byte
variable, truncating the value.
Instead, store the converted value in a temporary `long long` variable
so we can detect the scenario and decode into a `lua_Number`.
Signed-off-by: James McCoy <jamessan@jamessan.com>
|
| |
|
|
|
|
|
|
|
|
| |
Co-Authored-By: Hisham Muhammad <hisham@gobolinux.org>
Co-authored-by: Mark Pulford <mark@kyne.com.au>
Co-authored-by: ichenq <ichenq@gmail.com>
Co-authored-by: Cloud Wu <cloudwu@gmail.com>
Co-authored-by: caijietao <t0350.prog@gmail.com>
Co-authored-by: actboy168 <actboy168@gmail.com>
Co-authored-by: wudeng <wudeng256@gmail.com>
Co-authored-by: caiyiheng <rangercyh@qq.com>
|
| | |
|
| |
|
|
|
|
|
| |
* Fix integer overflows due to using wrong integer size.
* Add assertions / panic when overflow still happens.
Co-authored-by: Oran Agra <oran@redislabs.com>
Co-authored-by: Yossi Gottlieb <yossigo@gmail.com>
|
| |
|
| |
Co-authored-by: Jesper Lundgren <jesperlundgren@exosite.com>
|
| | |
|
| |
|
|
|
|
|
|
| |
light userdata address with masked address (#82)
Since we used `json_lightudata_mask` when creating lightuserdata, same
mask should be applied when comparing the return of `touserdata`
Fixes #81.
|
| | |
|
| | |
|
| | |
|
| | |
|
| | |
|
| |
|
|
| |
Thanks @spacewander for optimization and documentation.
|
| |
|
|
| |
least 64bits.
|
| |
|
|
|
|
| |
47-bit in the lightud.
Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
|
| | |
|
| |
|
|
| |
Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
|
| |
|
|
| |
code" on older operating systems.
|
| |
|
|
|
|
|
| |
this can be turned on via cjson.decode_array_with_array_mt(true). off by
default.
Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
|
| |
|
|
|
|
| |
encoding.
Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
|
| |
|
|
| |
Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
|
| |
|
|
| |
v2.1 already includes it. fixes #21.
|
| |
|
|
| |
Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
Prior to this fix, when the module would be loaded several times
(by-passing `package.loaded`), the `lua_cjson_new` function would
override the `empty_array_mt` table in the registry with a new one.
Comparison for equality between those tables would then fail, and the
behavior would be broken.
This was discovered after loading `cjson` *and* `cjson.safe` in the same
application, resulting in two calls to `lua_cjson_new`.
Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
|
| |
|
|
| |
Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
A proposed improved patch of openresty/lua-cjson#1 (a patch commonly
proposed to lua-cjson and its forks), taking into considerations
comments from the original PR.
- use a lightuserdata key to store the metatable in the Lua Registry
(more efficient and avoiding conflicts)
- provide a lightuserdata resulting in empty arrays as well
- tests cases moved to t/agentzh.t, where cases for
'encode_empty_table_as_object' are already written. It seems like a
better place for tests specific to the OpenResty fork's additions.
- a more complex test case
|
| |
|
|
|
|
|
|
| |
cjson.encode_number_precision().
thanks lordnynex for the patch in #4.
Test cases for changing precision
|
| |
|
|
| |
encode_empty_table_as_object so that we can encode empty Lua tables into empty JSON arrays.
|
| |
|
|
|
| |
Use Javascript compatible values for Infinity/NaN when encoding invalid
numbers.
|
| | |
|
| |
|
|
| |
Add cjson.safe module to suppress exceptions during JSON conversions.
|
| | |
|
| |
|
|
|
| |
Bump version to 2.0devel due to significant changes and updated API
(runtime config not fully backwards compatible).
|
| |
|
|
|
|
|
|
|
|
| |
Unlike "decode", encoding leaves both the key/value on the stack before
descending. This leaves no spare room for luaL_error() in case the depth
check or lua_checkstack() fails. Allocate an extra stack slot to ensure there is always room for
luaL_error() in json_check_encode_depth().
Note: this would not have caused a crash or fault due to the EXTRA_STACK
slot reserve, but it was a misuse of the Lua C API.
|
| |
|
|
|
|
| |
Remove deprecated "refuse_invalid_numbers" since the version number will
be bumped to 1.1.0. Also remove "version" variable since it has been
replaced by _VERSION.
|
| | |
|
| |
|
|
|
|
|
| |
Disable registration of cjson module table global variable in the
default build. Automatically creating a variable in the global namespace
can cause issues for other software and is no longer recommended with
Lua.
|
| |
|
|
|
|
| |
Return boolean values from configuration functions to simplify usage in
the common case. Eg,:
if not cjson.encode_invalid_numbers() then .. end
|
| |
|
|
|
|
|
|
|
| |
Include depth and character index when throwing decode nesting errors.
Pre-emptively add a test decoding a massively nested JSON array. Lua
stack overflow faults are unlikely to occur on simple data structures.
Valgrind can highlight stack allocation bugs with complicated JSON even
if the test succeeds.
|
| |
|
|
|
|
|
|
|
| |
Ensure there are enough Lua stack slots available before descending into
another table during encoding. This fixes a segfault when encoding
deeply nested tables.
This bug wasn't noticed earlier due to the previous limit of 20 nested
tables.
|
| |
|
|
|
|
|
| |
Simplify configuration functions by adding an argument position
parameter to json_enum_option() and json_integer_option(). Create
json_arg_init() to check the number of arguments and return the config
data.
|
| |
|
|
| |
Also ensure cjson.decode() only receives a single argument.
|
| | |
|
| |
|
|
|
| |
Increase the default nesting limits to reduce the chance of accidently
throwing an error on valid JSON out of the box.
|
| |
|
|
|
| |
Deprecate and replace refuse_invalid_numbers() with
encode_invalid_numbers() and decode_invalid_numbers().
|