From 75b3f5b0c29782b8a31009ba6ff2972a5ce736e3 Mon Sep 17 00:00:00 2001 From: jgeboski Date: Mon, 22 Jun 2015 15:35:13 -0400 Subject: facebook-api: fixed JSON parse errors with messages It was assumed there was always a leading "NULL" byte prepended to each message. This is not the case, the NULL byte is actually a variable integer, which is the size for a Thrift string. In order to navigate directly the JSON data, just read the data as a thrift string in order to obtain the offset of the JSON data. --- facebook/facebook-api.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'facebook') diff --git a/facebook/facebook-api.c b/facebook/facebook-api.c index 381568f..dfb4e9a 100644 --- a/facebook/facebook-api.c +++ b/facebook/facebook-api.c @@ -445,6 +445,7 @@ static void fb_api_cb_publish_ms(fb_api_t *api, const GByteArray *pload) { GSList *msgs; fb_api_msg_t msg; + fb_thrift_t *thft; json_value *json; json_value *jv; json_value *jx; @@ -454,8 +455,14 @@ static void fb_api_cb_publish_ms(fb_api_t *api, const GByteArray *pload) gint64 in; guint i; - /* Start at 1 to skip the NULL byte */ - if (!fb_api_json_new(api, (gchar*) pload->data + 1, pload->len - 1, &json)) + thft = fb_thrift_new((GByteArray*) pload, 0, TRUE); + fb_thrift_read_str(thft, NULL); + i = thft->pos; + fb_thrift_free(thft); + + g_return_if_fail(i < pload->len); + + if (!fb_api_json_new(api, (gchar*) pload->data + i, pload->len - i, &json)) return; msgs = NULL; -- cgit v1.2.3