From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: vdavydov.dev@gmail.com
Subject: [PATCH v2 01/10] yaml: don't throw OOM on any error in yaml encoding
Date: Fri, 20 Apr 2018 16:24:25 +0300 [thread overview]
Message-ID: <d21137f86bf6cfb1631314d3d1639627ab6b3099.1524228894.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1524228894.git.v.shpilevoy@tarantool.org>
In-Reply-To: <cover.1524228894.git.v.shpilevoy@tarantool.org>
OOM is not single possible error. Yaml library during dump can
raise such errors as YAML_MEMORY_ERROR, YAML_WRITER_ERROR,
YAML_EMITTER_ERROR. And each of them can contain any error
message that is skipped now, because Tarantool YAML does not
provide such API, that can lead to a non-OOM error.
But it is changed in next commits.
---
third_party/lua-yaml/lyaml.cc | 49 ++++++++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 22 deletions(-)
diff --git a/third_party/lua-yaml/lyaml.cc b/third_party/lua-yaml/lyaml.cc
index 4d875fab4..430f4be2c 100644
--- a/third_party/lua-yaml/lyaml.cc
+++ b/third_party/lua-yaml/lyaml.cc
@@ -401,7 +401,7 @@ static int dump_table(struct lua_yaml_dumper *dumper, struct luaL_field *field){
? (YAML_FLOW_MAPPING_STYLE) : YAML_BLOCK_MAPPING_STYLE;
if (!yaml_mapping_start_event_initialize(&ev, anchor, NULL, 0, yaml_style) ||
!yaml_emitter_emit(&dumper->emitter, &ev))
- luaL_error(dumper->L, OOM_ERRMSG);
+ return 0;
lua_pushnil(dumper->L);
while (lua_next(dumper->L, -2)) {
@@ -414,11 +414,8 @@ static int dump_table(struct lua_yaml_dumper *dumper, struct luaL_field *field){
lua_pop(dumper->L, 1);
}
- if (!yaml_mapping_end_event_initialize(&ev) ||
- !yaml_emitter_emit(&dumper->emitter, &ev))
- luaL_error(dumper->L, OOM_ERRMSG);
-
- return 1;
+ return yaml_mapping_end_event_initialize(&ev) != 0 &&
+ yaml_emitter_emit(&dumper->emitter, &ev) != 0 ? 1 : 0;
}
static int dump_array(struct lua_yaml_dumper *dumper, struct luaL_field *field){
@@ -433,7 +430,7 @@ static int dump_array(struct lua_yaml_dumper *dumper, struct luaL_field *field){
? (YAML_FLOW_SEQUENCE_STYLE) : YAML_BLOCK_SEQUENCE_STYLE;
if (!yaml_sequence_start_event_initialize(&ev, anchor, NULL, 0, yaml_style) ||
!yaml_emitter_emit(&dumper->emitter, &ev))
- luaL_error(dumper->L, OOM_ERRMSG);
+ return 0;
for (i = 0; i < field->size; i++) {
lua_rawgeti(dumper->L, -1, i + 1);
@@ -442,11 +439,8 @@ static int dump_array(struct lua_yaml_dumper *dumper, struct luaL_field *field){
lua_pop(dumper->L, 1);
}
- if (!yaml_sequence_end_event_initialize(&ev) ||
- !yaml_emitter_emit(&dumper->emitter, &ev))
- luaL_error(dumper->L, OOM_ERRMSG);
-
- return 1;
+ return yaml_sequence_end_event_initialize(&ev) != 0 &&
+ yaml_emitter_emit(&dumper->emitter, &ev) != 0 ? 1 : 0;
}
static int yaml_is_flow_mode(struct lua_yaml_dumper *dumper) {
@@ -566,7 +560,7 @@ static int dump_node(struct lua_yaml_dumper *dumper)
if (!yaml_scalar_event_initialize(&ev, NULL, tag, (unsigned char *)str, len,
!is_binary, !is_binary, style) ||
!yaml_emitter_emit(&dumper->emitter, &ev))
- luaL_error(dumper->L, OOM_ERRMSG);
+ return 0;
if (is_binary)
lua_pop(dumper->L, 1);
@@ -579,14 +573,14 @@ static void dump_document(struct lua_yaml_dumper *dumper) {
if (!yaml_document_start_event_initialize(&ev, NULL, NULL, NULL, 0) ||
!yaml_emitter_emit(&dumper->emitter, &ev))
- luaL_error(dumper->L, OOM_ERRMSG);
+ return;
if (!dump_node(dumper) || dumper->error)
return;
if (!yaml_document_end_event_initialize(&ev, 0) ||
!yaml_emitter_emit(&dumper->emitter, &ev))
- luaL_error(dumper->L, OOM_ERRMSG);
+ return;
}
static int append_output(void *arg, unsigned char *buf, size_t len) {
@@ -637,7 +631,7 @@ static int l_dump(lua_State *L) {
luaL_buffinit(dumper.outputL, &dumper.yamlbuf);
if (!yaml_emitter_initialize(&dumper.emitter))
- luaL_error(L, OOM_ERRMSG);
+ goto error;
yaml_emitter_set_unicode(&dumper.emitter, 1);
yaml_emitter_set_indent(&dumper.emitter, 2);
@@ -647,7 +641,7 @@ static int l_dump(lua_State *L) {
if (!yaml_stream_start_event_initialize(&ev, YAML_UTF8_ENCODING) ||
!yaml_emitter_emit(&dumper.emitter, &ev))
- luaL_error(L, OOM_ERRMSG);
+ goto error;
for (i = 0; i < argcount; i++) {
lua_newtable(L);
@@ -657,26 +651,37 @@ static int l_dump(lua_State *L) {
find_references(&dumper);
dump_document(&dumper);
if (dumper.error)
- break;
+ goto error;
lua_pop(L, 2); /* pop copied arg and anchor table */
}
if (!yaml_stream_end_event_initialize(&ev) ||
!yaml_emitter_emit(&dumper.emitter, &ev) ||
!yaml_emitter_flush(&dumper.emitter))
- luaL_error(L, OOM_ERRMSG);
-
- yaml_emitter_delete(&dumper.emitter);
+ goto error;
/* finalize and push YAML buffer */
luaL_pushresult(&dumper.yamlbuf);
if (dumper.error)
- lua_error(L);
+ goto error;
+ yaml_emitter_delete(&dumper.emitter);
/* move buffer to original thread */
lua_xmove(dumper.outputL, L, 1);
return 1;
+
+error:
+ if (dumper.emitter.error == YAML_NO_ERROR ||
+ dumper.emitter.error == YAML_MEMORY_ERROR) {
+ yaml_emitter_delete(&dumper.emitter);
+ return luaL_error(L, OOM_ERRMSG);
+ } else {
+ lua_pushnil(L);
+ lua_pushstring(L, dumper.emitter.problem);
+ yaml_emitter_delete(&dumper.emitter);
+ return 2;
+ }
}
static int
--
2.15.1 (Apple Git-101)
next prev parent reply other threads:[~2018-04-20 13:24 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-20 13:24 [PATCH v2 00/10] session: introduce box.session.push Vladislav Shpilevoy
2018-04-20 13:24 ` Vladislav Shpilevoy [this message]
2018-05-10 18:10 ` [tarantool-patches] [PATCH v2 01/10] yaml: don't throw OOM on any error in yaml encoding Konstantin Osipov
2018-04-20 13:24 ` [tarantool-patches] [PATCH v2 10/10] session: introduce binary box.session.push Vladislav Shpilevoy
2018-05-10 19:50 ` Konstantin Osipov
2018-05-24 20:50 ` [tarantool-patches] " Vladislav Shpilevoy
2018-04-20 13:24 ` [PATCH v2 02/10] yaml: introduce yaml.encode_tagged Vladislav Shpilevoy
2018-05-10 18:22 ` [tarantool-patches] " Konstantin Osipov
2018-05-24 20:50 ` [tarantool-patches] " Vladislav Shpilevoy
2018-05-30 19:15 ` Konstantin Osipov
2018-05-30 20:49 ` Vladislav Shpilevoy
2018-05-31 10:46 ` Konstantin Osipov
2018-04-20 13:24 ` [PATCH v2 03/10] yaml: introduce yaml.decode_tag Vladislav Shpilevoy
2018-05-10 18:41 ` [tarantool-patches] " Konstantin Osipov
2018-05-24 20:50 ` [tarantool-patches] " Vladislav Shpilevoy
2018-05-31 10:54 ` Konstantin Osipov
2018-05-31 11:36 ` Konstantin Osipov
2018-04-20 13:24 ` [PATCH v2 04/10] console: use Lua C API to do formatting for console Vladislav Shpilevoy
2018-05-10 18:46 ` [tarantool-patches] " Konstantin Osipov
2018-05-24 20:50 ` [tarantool-patches] " Vladislav Shpilevoy
2018-04-20 13:24 ` [PATCH v2 05/10] session: move salt into iproto connection Vladislav Shpilevoy
2018-05-10 18:47 ` [tarantool-patches] " Konstantin Osipov
2018-04-20 13:24 ` [PATCH v2 06/10] session: introduce session vtab and meta Vladislav Shpilevoy
2018-05-10 19:20 ` [tarantool-patches] " Konstantin Osipov
2018-05-24 20:50 ` [tarantool-patches] " Vladislav Shpilevoy
2018-04-20 13:24 ` [PATCH v2 07/10] port: rename dump() into dump_msgpack() Vladislav Shpilevoy
2018-05-10 19:21 ` [tarantool-patches] " Konstantin Osipov
2018-04-20 13:24 ` [PATCH v2 08/10] session: introduce text box.session.push Vladislav Shpilevoy
2018-05-10 19:27 ` [tarantool-patches] " Konstantin Osipov
2018-05-24 20:50 ` [tarantool-patches] " Vladislav Shpilevoy
2018-04-20 13:24 ` [PATCH v2 09/10] session: enable box.session.push in local console Vladislav Shpilevoy
2018-05-10 19:28 ` [tarantool-patches] " Konstantin Osipov
2018-05-24 20:50 ` [tarantool-patches] [PATCH 1/1] netbox: introduce iterable future objects Vladislav Shpilevoy
2018-06-04 22:17 ` [tarantool-patches] " Vladislav Shpilevoy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d21137f86bf6cfb1631314d3d1639627ab6b3099.1524228894.git.v.shpilevoy@tarantool.org \
--to=v.shpilevoy@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=vdavydov.dev@gmail.com \
--subject='Re: [PATCH v2 01/10] yaml: don'\''t throw OOM on any error in yaml encoding' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox