Skip to content

Ruby: Seg fault in add_serialized_file with v3.18.0+ #9141

Description

@stanhu

What version of protobuf and what language are you using?
Version: master, v3.18.0, v3.19.0
Language: Ruby

What operating system (Linux, Windows, ...) and version?

s390x Linux on Z

What runtime / compiler are you using (e.g., python version or gcc version)

$ gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

What did you do?
Steps to reproduce the behavior:

  1. Use a IBM s390x machine running Linux on Z.
  2. Clone the repo.
  3. In the ruby dir, run bundle exec rake.

What did you expect to see

All tests successful

What did you see instead?

This seg fault:

/build/protobuf/ruby/lib/google/protobuf/descriptor_pb.rb:7: [BUG] Segmentation fault at 0x00000403ade27000
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [s390x-linux]

-- Control frame information -----------------------------------------------
c:0015 p:---- s:0062 e:000061 CFUNC  :add_serialized_file
c:0014 p:0053 s:0057 e:000056 TOP    /build/protobuf/ruby/lib/google/protobuf/descriptor_pb.rb:7 [FINISH]
c:0013 p:---- s:0053 e:000052 CFUNC  :require
c:0012 p:0005 s:0048 e:000047 TOP    /build/protobuf/ruby/lib/google/protobuf/descriptor_dsl.rb:5 [FINISH]
c:0011 p:---- s:0045 e:000044 CFUNC  :require
c:0010 p:0083 s:0040 e:000039 TOP    /build/protobuf/ruby/lib/google/protobuf.rb:56 [FINISH]
c:0009 p:---- s:0037 e:000036 CFUNC  :require
c:0008 p:0005 s:0032 e:000031 TOP    /build/protobuf/ruby/tests/basic_test_pb.rb:4 [FINISH]
c:0007 p:---- s:0029 e:000028 CFUNC  :require
c:0006 p:0034 s:0024 e:000023 TOP    /build/protobuf/ruby/tests/basic.rb:6 [FINISH]
c:0005 p:---- s:0021 e:000020 CFUNC  :require
c:0004 p:0076 s:0016 e:000015 BLOCK  /usr/local/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:21 [FINISH]
c:0003 p:---- s:0011 e:000010 CFUNC  :select
c:0002 p:0018 s:0007 E:000cb8 EVAL   /usr/local/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6 [FINISH]
c:0001 p:0000 s:0003 E:000750 (none) [FINISH]

ruby-protobuf.txt

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

This is the log when I run valgrind ruby tests/basic.rb:

==140403== Invalid read of size 4
==140403==    at 0x9F97614: upb_fielddef_type (ruby-upb.c:4748)
==140403==    by 0x9F97614: upb_fielddef_isstring (ruby-upb.c:4923)
==140403==    by 0x9F97614: upb_fielddef_isprimitive (ruby-upb.c:4932)
==140403==    by 0x9F97614: create_fielddef (ruby-upb.c:6120)
==140403==    by 0x9F9771B: create_fielddef (ruby-upb.c:6029)
==140403==  Address 0x409fa3a2c is not stack'd, malloc'd or (recently) free'd

Full valgrind log:

valgrind-protobuf.txt

Anything else we should know about your project / environment

This is a Big Endian machine, and I checked that https://github.com/protocolbuffers/upb/pull/306/files seems to be in the ruby-ubp.c file.

I didn't see these seg faults when I ran this test with v3.17.3. It seems to have been introduced in v3.18.0.

/cc: @haberman

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions