Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated upb to allow nonzero offset minutes in JSON timestamps. #8258

Merged
merged 3 commits into from Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions php/ext/google/protobuf/php-upb.c
Expand Up @@ -6711,6 +6711,10 @@ size_t _upb_symtab_bytesloaded(const upb_symtab *s) {
return s->bytes_loaded;
}

upb_arena *_upb_symtab_arena(const upb_symtab *s) {
return s->arena;
}

#undef CHK_OOM


Expand Down Expand Up @@ -8020,7 +8024,7 @@ static void jsondec_field(jsondec *d, upb_msg *msg, const upb_msgdef *m) {

if (!f) {
if ((d->options & UPB_JSONDEC_IGNOREUNKNOWN) == 0) {
jsondec_errf(d, "Unknown field: '" UPB_STRVIEW_FORMAT "'",
jsondec_errf(d, "No such field: " UPB_STRVIEW_FORMAT,
UPB_STRVIEW_ARGS(name));
}
jsondec_skipval(d);
Expand Down Expand Up @@ -8173,7 +8177,8 @@ static void jsondec_timestamp(jsondec *d, upb_msg *msg, const upb_msgdef *m) {

{
/* [+-]08:00 or Z */
int ofs = 0;
int ofs_hour = 0;
int ofs_min = 0;
bool neg = false;

if (ptr == end) goto malformed;
Expand All @@ -8184,9 +8189,10 @@ static void jsondec_timestamp(jsondec *d, upb_msg *msg, const upb_msgdef *m) {
/* fallthrough */
case '+':
if ((end - ptr) != 5) goto malformed;
ofs = jsondec_tsdigits(d, &ptr, 2, ":00");
ofs *= 60 * 60;
seconds.int64_val += (neg ? ofs : -ofs);
ofs_hour = jsondec_tsdigits(d, &ptr, 2, ":");
ofs_min = jsondec_tsdigits(d, &ptr, 2, NULL);
ofs_min = ((ofs_hour * 60) + ofs_min) * 60;
seconds.int64_val += (neg ? ofs_min : -ofs_min);
break;
case 'Z':
if (ptr != end) goto malformed;
Expand Down
1 change: 1 addition & 0 deletions php/ext/google/protobuf/php-upb.h
Expand Up @@ -4178,6 +4178,7 @@ const upb_filedef *upb_symtab_addfile(
upb_symtab *s, const google_protobuf_FileDescriptorProto *file,
upb_status *status);
size_t _upb_symtab_bytesloaded(const upb_symtab *s);
upb_arena *_upb_symtab_arena(const upb_symtab *s);

/* For generated code only: loads a generated descriptor. */
typedef struct upb_def_init {
Expand Down
10 changes: 6 additions & 4 deletions ruby/ext/google/protobuf_c/ruby-upb.c
Expand Up @@ -7793,7 +7793,8 @@ static void jsondec_timestamp(jsondec *d, upb_msg *msg, const upb_msgdef *m) {

{
/* [+-]08:00 or Z */
int ofs = 0;
int ofs_hour = 0;
int ofs_min = 0;
bool neg = false;

if (ptr == end) goto malformed;
Expand All @@ -7804,9 +7805,10 @@ static void jsondec_timestamp(jsondec *d, upb_msg *msg, const upb_msgdef *m) {
/* fallthrough */
case '+':
if ((end - ptr) != 5) goto malformed;
ofs = jsondec_tsdigits(d, &ptr, 2, ":00");
ofs *= 60 * 60;
seconds.int64_val += (neg ? ofs : -ofs);
ofs_hour = jsondec_tsdigits(d, &ptr, 2, ":");
ofs_min = jsondec_tsdigits(d, &ptr, 2, NULL);
ofs_min = ((ofs_hour * 60) + ofs_min) * 60;
seconds.int64_val += (neg ? ofs_min : -ofs_min);
break;
case 'Z':
if (ptr != end) goto malformed;
Expand Down
2 changes: 1 addition & 1 deletion ruby/ext/google/protobuf_c/ruby-upb.h
Expand Up @@ -4161,7 +4161,6 @@ const upb_filedef *upb_filedef_dep(const upb_filedef *f, int i);
const upb_msgdef *upb_filedef_msg(const upb_filedef *f, int i);
const upb_enumdef *upb_filedef_enum(const upb_filedef *f, int i);
const upb_symtab *upb_filedef_symtab(const upb_filedef *f);
upb_arena *_upb_symtab_arena(const upb_symtab *s);

/* upb_symtab *****************************************************************/

Expand All @@ -4179,6 +4178,7 @@ const upb_filedef *upb_symtab_addfile(
upb_symtab *s, const google_protobuf_FileDescriptorProto *file,
upb_status *status);
size_t _upb_symtab_bytesloaded(const upb_symtab *s);
upb_arena *_upb_symtab_arena(const upb_symtab *s);

/* For generated code only: loads a generated descriptor. */
typedef struct upb_def_init {
Expand Down