The following issues were found
ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java
54 issues
Line: 111
* the array and fills the hole (if any) with default values.
*/
@JRubyMethod(name = "[]=")
public IRubyObject indexSet(ThreadContext context, IRubyObject index, IRubyObject value) {
int arrIndex = normalizeArrayIndex(index);
value = Utils.checkType(context, fieldType, name, value, (RubyModule) typeClass);
IRubyObject defaultValue = defaultValue(context);
for (int i = this.storage.size(); i < arrIndex; i++) {
this.storage.set(i, defaultValue);
Reported by PMD.
Line: 46
import java.util.Arrays;
@JRubyClass(name = "RepeatedClass", include = "Enumerable")
public class RubyRepeatedField extends RubyObject {
public static void createRubyRepeatedField(Ruby runtime) {
RubyModule mProtobuf = runtime.getClassFromPath("Google::Protobuf");
RubyClass cRepeatedField = mProtobuf.defineClassUnder("RepeatedField", runtime.getObject(),
new ObjectAllocator() {
@Override
Reported by PMD.
Line: 46
import java.util.Arrays;
@JRubyClass(name = "RepeatedClass", include = "Enumerable")
public class RubyRepeatedField extends RubyObject {
public static void createRubyRepeatedField(Ruby runtime) {
RubyModule mProtobuf = runtime.getClassFromPath("Google::Protobuf");
RubyClass cRepeatedField = mProtobuf.defineClassUnder("RepeatedField", runtime.getObject(),
new ObjectAllocator() {
@Override
Reported by PMD.
Line: 72
}
@JRubyMethod(required = 1, optional = 2)
public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.runtime;
this.storage = runtime.newArray();
IRubyObject ary = null;
if (!(args[0] instanceof RubySymbol)) {
throw runtime.newArgumentError("Expected Symbol for type name");
Reported by PMD.
Line: 74
@JRubyMethod(required = 1, optional = 2)
public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.runtime;
this.storage = runtime.newArray();
IRubyObject ary = null;
if (!(args[0] instanceof RubySymbol)) {
throw runtime.newArgumentError("Expected Symbol for type name");
}
this.fieldType = Utils.rubyToFieldType(args[0]);
Reported by PMD.
Line: 82
this.fieldType = Utils.rubyToFieldType(args[0]);
if (fieldType == FieldDescriptor.Type.MESSAGE
|| fieldType == FieldDescriptor.Type.ENUM) {
if (args.length < 2)
throw runtime.newArgumentError("Expected at least 2 arguments for message/enum");
typeClass = args[1];
if (args.length > 2)
ary = args[2];
Utils.validateTypeClass(context, fieldType, typeClass);
Reported by PMD.
Line: 85
if (args.length < 2)
throw runtime.newArgumentError("Expected at least 2 arguments for message/enum");
typeClass = args[1];
if (args.length > 2)
ary = args[2];
Utils.validateTypeClass(context, fieldType, typeClass);
} else {
if (args.length > 2)
throw runtime.newArgumentError("Too many arguments: expected 1 or 2");
Reported by PMD.
Line: 89
ary = args[2];
Utils.validateTypeClass(context, fieldType, typeClass);
} else {
if (args.length > 2)
throw runtime.newArgumentError("Too many arguments: expected 1 or 2");
if (args.length > 1)
ary = args[1];
}
if (ary != null) {
Reported by PMD.
Line: 91
} else {
if (args.length > 2)
throw runtime.newArgumentError("Too many arguments: expected 1 or 2");
if (args.length > 1)
ary = args[1];
}
if (ary != null) {
RubyArray arr = ary.convertToArray();
for (int i = 0; i < arr.size(); i++) {
Reported by PMD.
Line: 96
}
if (ary != null) {
RubyArray arr = ary.convertToArray();
for (int i = 0; i < arr.size(); i++) {
this.storage.add(arr.eltInternal(i));
}
}
return this;
}
Reported by PMD.
python/google/protobuf/internal/descriptor_database_test.py
53 issues
Line: 43
Column: 1
import unittest
import warnings
from google.protobuf import unittest_pb2
from google.protobuf import descriptor_pb2
from google.protobuf.internal import factory_test2_pb2
from google.protobuf.internal import no_package_pb2
from google.protobuf.internal import testing_refleaks
from google.protobuf import descriptor_database
Reported by Pylint.
Line: 44
Column: 1
import warnings
from google.protobuf import unittest_pb2
from google.protobuf import descriptor_pb2
from google.protobuf.internal import factory_test2_pb2
from google.protobuf.internal import no_package_pb2
from google.protobuf.internal import testing_refleaks
from google.protobuf import descriptor_database
Reported by Pylint.
Line: 45
Column: 1
from google.protobuf import unittest_pb2
from google.protobuf import descriptor_pb2
from google.protobuf.internal import factory_test2_pb2
from google.protobuf.internal import no_package_pb2
from google.protobuf.internal import testing_refleaks
from google.protobuf import descriptor_database
Reported by Pylint.
Line: 46
Column: 1
from google.protobuf import unittest_pb2
from google.protobuf import descriptor_pb2
from google.protobuf.internal import factory_test2_pb2
from google.protobuf.internal import no_package_pb2
from google.protobuf.internal import testing_refleaks
from google.protobuf import descriptor_database
@testing_refleaks.TestCase
Reported by Pylint.
Line: 108
Column: 10
self.assertEqual(file_desc_proto2, db.FindFileContainingSymbol(
'protobuf_unittest.TestAllTypes.none_field'))
with self.assertRaisesRegexp(KeyError, r'\'protobuf_unittest\.NoneMessage\''):
db.FindFileContainingSymbol('protobuf_unittest.NoneMessage')
def testConflictRegister(self):
db = descriptor_database.DescriptorDatabase()
unittest_fd = descriptor_pb2.FileDescriptorProto.FromString(
Reported by Pylint.
Line: 38
Column: 1
__author__ = 'matthewtoia@google.com (Matt Toia)'
try:
import unittest2 as unittest #PY26
except ImportError:
import unittest
import warnings
from google.protobuf import unittest_pb2
Reported by Pylint.
Line: 40
Column: 1
try:
import unittest2 as unittest #PY26
except ImportError:
import unittest
import warnings
from google.protobuf import unittest_pb2
from google.protobuf import descriptor_pb2
from google.protobuf.internal import factory_test2_pb2
Reported by Pylint.
Line: 52
Column: 1
@testing_refleaks.TestCase
class DescriptorDatabaseTest(unittest.TestCase):
def testAdd(self):
db = descriptor_database.DescriptorDatabase()
file_desc_proto = descriptor_pb2.FileDescriptorProto.FromString(
factory_test2_pb2.DESCRIPTOR.serialized_pb)
Reported by Pylint.
Line: 54
Column: 1
@testing_refleaks.TestCase
class DescriptorDatabaseTest(unittest.TestCase):
def testAdd(self):
db = descriptor_database.DescriptorDatabase()
file_desc_proto = descriptor_pb2.FileDescriptorProto.FromString(
factory_test2_pb2.DESCRIPTOR.serialized_pb)
file_desc_proto2 = descriptor_pb2.FileDescriptorProto.FromString(
no_package_pb2.DESCRIPTOR.serialized_pb)
Reported by Pylint.
Line: 54
Column: 3
@testing_refleaks.TestCase
class DescriptorDatabaseTest(unittest.TestCase):
def testAdd(self):
db = descriptor_database.DescriptorDatabase()
file_desc_proto = descriptor_pb2.FileDescriptorProto.FromString(
factory_test2_pb2.DESCRIPTOR.serialized_pb)
file_desc_proto2 = descriptor_pb2.FileDescriptorProto.FromString(
no_package_pb2.DESCRIPTOR.serialized_pb)
Reported by Pylint.
java/core/src/test/java/com/google/protobuf/AbstractProto2LiteSchemaTest.java
53 issues
Line: 54
}
@Test
public void mergeOptionalMessageFields() throws Exception {
Proto2MessageLite message1 =
newBuilder()
.setFieldMessage10(newBuilder().setFieldInt643(123).clearFieldInt325().build())
.build();
Proto2MessageLite message2 =
Reported by PMD.
Line: 54
}
@Test
public void mergeOptionalMessageFields() throws Exception {
Proto2MessageLite message1 =
newBuilder()
.setFieldMessage10(newBuilder().setFieldInt643(123).clearFieldInt325().build())
.build();
Proto2MessageLite message2 =
Reported by PMD.
Line: 68
.setFieldMessage10(newBuilder().setFieldInt643(789).clearFieldInt325().build())
.build();
ByteArrayOutputStream output = new ByteArrayOutputStream();
message1.writeTo(output);
message2.writeTo(output);
message3.writeTo(output);
byte[] data = output.toByteArray();
Proto2MessageLite merged =
Reported by PMD.
Line: 69
.build();
ByteArrayOutputStream output = new ByteArrayOutputStream();
message1.writeTo(output);
message2.writeTo(output);
message3.writeTo(output);
byte[] data = output.toByteArray();
Proto2MessageLite merged =
ExperimentalSerializationUtil.fromByteArray(data, Proto2MessageLite.class);
Reported by PMD.
Line: 70
ByteArrayOutputStream output = new ByteArrayOutputStream();
message1.writeTo(output);
message2.writeTo(output);
message3.writeTo(output);
byte[] data = output.toByteArray();
Proto2MessageLite merged =
ExperimentalSerializationUtil.fromByteArray(data, Proto2MessageLite.class);
assertThat(merged.getFieldMessage10().getFieldInt643()).isEqualTo(789);
Reported by PMD.
Line: 75
Proto2MessageLite merged =
ExperimentalSerializationUtil.fromByteArray(data, Proto2MessageLite.class);
assertThat(merged.getFieldMessage10().getFieldInt643()).isEqualTo(789);
assertThat(merged.getFieldMessage10().getFieldInt325()).isEqualTo(456);
}
@Test
public void oneofFieldsShouldRoundtrip() throws IOException {
Reported by PMD.
Line: 75
Proto2MessageLite merged =
ExperimentalSerializationUtil.fromByteArray(data, Proto2MessageLite.class);
assertThat(merged.getFieldMessage10().getFieldInt643()).isEqualTo(789);
assertThat(merged.getFieldMessage10().getFieldInt325()).isEqualTo(456);
}
@Test
public void oneofFieldsShouldRoundtrip() throws IOException {
Reported by PMD.
Line: 75
Proto2MessageLite merged =
ExperimentalSerializationUtil.fromByteArray(data, Proto2MessageLite.class);
assertThat(merged.getFieldMessage10().getFieldInt643()).isEqualTo(789);
assertThat(merged.getFieldMessage10().getFieldInt325()).isEqualTo(456);
}
@Test
public void oneofFieldsShouldRoundtrip() throws IOException {
Reported by PMD.
Line: 76
Proto2MessageLite merged =
ExperimentalSerializationUtil.fromByteArray(data, Proto2MessageLite.class);
assertThat(merged.getFieldMessage10().getFieldInt643()).isEqualTo(789);
assertThat(merged.getFieldMessage10().getFieldInt325()).isEqualTo(456);
}
@Test
public void oneofFieldsShouldRoundtrip() throws IOException {
roundtrip("Field 53", newBuilder().setFieldDouble53(100).build());
Reported by PMD.
Line: 76
Proto2MessageLite merged =
ExperimentalSerializationUtil.fromByteArray(data, Proto2MessageLite.class);
assertThat(merged.getFieldMessage10().getFieldInt643()).isEqualTo(789);
assertThat(merged.getFieldMessage10().getFieldInt325()).isEqualTo(456);
}
@Test
public void oneofFieldsShouldRoundtrip() throws IOException {
roundtrip("Field 53", newBuilder().setFieldDouble53(100).build());
Reported by PMD.
java/core/src/test/java/com/google/protobuf/TextFormatParseInfoTreeTest.java
53 issues
Line: 46
/** Test @{link TextFormatParseInfoTree}. */
@RunWith(JUnit4.class)
public class TextFormatParseInfoTreeTest {
private static final Descriptor DESCRIPTOR = TestAllTypes.getDescriptor();
private static final FieldDescriptor OPTIONAL_INT32 =
DESCRIPTOR.findFieldByName("optional_int32");
private static final FieldDescriptor OPTIONAL_BOOLEAN =
Reported by PMD.
Line: 65
private static final TextFormatParseLocation LOC0 = TextFormatParseLocation.create(1, 2);
private static final TextFormatParseLocation LOC1 = TextFormatParseLocation.create(2, 3);
private TextFormatParseInfoTree.Builder rootBuilder;
@Before
public void setUp() {
rootBuilder = TextFormatParseInfoTree.builder();
}
Reported by PMD.
Line: 75
@Test
public void testBuildEmptyParseTree() {
TextFormatParseInfoTree tree = rootBuilder.build();
assertThat(tree.getLocations(null)).isEmpty();
}
@Test
public void testGetLocationReturnsSingleLocation() {
rootBuilder.setLocation(OPTIONAL_INT32, LOC0);
Reported by PMD.
Line: 75
@Test
public void testBuildEmptyParseTree() {
TextFormatParseInfoTree tree = rootBuilder.build();
assertThat(tree.getLocations(null)).isEmpty();
}
@Test
public void testGetLocationReturnsSingleLocation() {
rootBuilder.setLocation(OPTIONAL_INT32, LOC0);
Reported by PMD.
Line: 79
}
@Test
public void testGetLocationReturnsSingleLocation() {
rootBuilder.setLocation(OPTIONAL_INT32, LOC0);
TextFormatParseInfoTree root = rootBuilder.build();
assertThat(root.getLocation(OPTIONAL_INT32, 0)).isEqualTo(LOC0);
assertThat(root.getLocations(OPTIONAL_INT32)).hasSize(1);
}
Reported by PMD.
Line: 82
public void testGetLocationReturnsSingleLocation() {
rootBuilder.setLocation(OPTIONAL_INT32, LOC0);
TextFormatParseInfoTree root = rootBuilder.build();
assertThat(root.getLocation(OPTIONAL_INT32, 0)).isEqualTo(LOC0);
assertThat(root.getLocations(OPTIONAL_INT32)).hasSize(1);
}
@Test
public void testGetLocationsReturnsNoParseLocationsForUnknownField() {
Reported by PMD.
Line: 82
public void testGetLocationReturnsSingleLocation() {
rootBuilder.setLocation(OPTIONAL_INT32, LOC0);
TextFormatParseInfoTree root = rootBuilder.build();
assertThat(root.getLocation(OPTIONAL_INT32, 0)).isEqualTo(LOC0);
assertThat(root.getLocations(OPTIONAL_INT32)).hasSize(1);
}
@Test
public void testGetLocationsReturnsNoParseLocationsForUnknownField() {
Reported by PMD.
Line: 83
rootBuilder.setLocation(OPTIONAL_INT32, LOC0);
TextFormatParseInfoTree root = rootBuilder.build();
assertThat(root.getLocation(OPTIONAL_INT32, 0)).isEqualTo(LOC0);
assertThat(root.getLocations(OPTIONAL_INT32)).hasSize(1);
}
@Test
public void testGetLocationsReturnsNoParseLocationsForUnknownField() {
assertThat(rootBuilder.build().getLocations(OPTIONAL_INT32)).isEmpty();
Reported by PMD.
Line: 83
rootBuilder.setLocation(OPTIONAL_INT32, LOC0);
TextFormatParseInfoTree root = rootBuilder.build();
assertThat(root.getLocation(OPTIONAL_INT32, 0)).isEqualTo(LOC0);
assertThat(root.getLocations(OPTIONAL_INT32)).hasSize(1);
}
@Test
public void testGetLocationsReturnsNoParseLocationsForUnknownField() {
assertThat(rootBuilder.build().getLocations(OPTIONAL_INT32)).isEmpty();
Reported by PMD.
Line: 87
}
@Test
public void testGetLocationsReturnsNoParseLocationsForUnknownField() {
assertThat(rootBuilder.build().getLocations(OPTIONAL_INT32)).isEmpty();
rootBuilder.setLocation(OPTIONAL_BOOLEAN, LOC0);
TextFormatParseInfoTree root = rootBuilder.build();
assertThat(root.getLocations(OPTIONAL_INT32)).isEmpty();
assertThat(root.getLocations(OPTIONAL_BOOLEAN).get(0)).isEqualTo(LOC0);
Reported by PMD.
java/core/src/main/java/com/google/protobuf/AbstractMessage.java
53 issues
Line: 283
/** Get a hash code for given fields and values, using the given seed. */
@SuppressWarnings("unchecked")
protected static int hashFields(int hash, Map<FieldDescriptor, Object> map) {
for (Map.Entry<FieldDescriptor, Object> entry : map.entrySet()) {
FieldDescriptor field = entry.getKey();
Object value = entry.getValue();
hash = (37 * hash) + field.getNumber();
if (field.isMapField()) {
Reported by PMD.
Line: 283
/** Get a hash code for given fields and values, using the given seed. */
@SuppressWarnings("unchecked")
protected static int hashFields(int hash, Map<FieldDescriptor, Object> map) {
for (Map.Entry<FieldDescriptor, Object> entry : map.entrySet()) {
FieldDescriptor field = entry.getKey();
Object value = entry.getValue();
hash = (37 * hash) + field.getNumber();
if (field.isMapField()) {
Reported by PMD.
Line: 283
/** Get a hash code for given fields and values, using the given seed. */
@SuppressWarnings("unchecked")
protected static int hashFields(int hash, Map<FieldDescriptor, Object> map) {
for (Map.Entry<FieldDescriptor, Object> entry : map.entrySet()) {
FieldDescriptor field = entry.getKey();
Object value = entry.getValue();
hash = (37 * hash) + field.getNumber();
if (field.isMapField()) {
Reported by PMD.
Line: 283
/** Get a hash code for given fields and values, using the given seed. */
@SuppressWarnings("unchecked")
protected static int hashFields(int hash, Map<FieldDescriptor, Object> map) {
for (Map.Entry<FieldDescriptor, Object> entry : map.entrySet()) {
FieldDescriptor field = entry.getKey();
Object value = entry.getValue();
hash = (37 * hash) + field.getNumber();
if (field.isMapField()) {
Reported by PMD.
Line: 283
/** Get a hash code for given fields and values, using the given seed. */
@SuppressWarnings("unchecked")
protected static int hashFields(int hash, Map<FieldDescriptor, Object> map) {
for (Map.Entry<FieldDescriptor, Object> entry : map.entrySet()) {
FieldDescriptor field = entry.getKey();
Object value = entry.getValue();
hash = (37 * hash) + field.getNumber();
if (field.isMapField()) {
Reported by PMD.
Line: 52
*
* @author kenton@google.com Kenton Varda
*/
public abstract class AbstractMessage
// TODO(dweis): Update GeneratedMessage to parameterize with MessageType and BuilderType.
extends AbstractMessageLite implements Message {
@Override
public boolean isInitialized() {
Reported by PMD.
Line: 52
*
* @author kenton@google.com Kenton Varda
*/
public abstract class AbstractMessage
// TODO(dweis): Update GeneratedMessage to parameterize with MessageType and BuilderType.
extends AbstractMessageLite implements Message {
@Override
public boolean isInitialized() {
Reported by PMD.
Line: 52
*
* @author kenton@google.com Kenton Varda
*/
public abstract class AbstractMessage
// TODO(dweis): Update GeneratedMessage to parameterize with MessageType and BuilderType.
extends AbstractMessageLite implements Message {
@Override
public boolean isInitialized() {
Reported by PMD.
Line: 54
*/
public abstract class AbstractMessage
// TODO(dweis): Update GeneratedMessage to parameterize with MessageType and BuilderType.
extends AbstractMessageLite implements Message {
@Override
public boolean isInitialized() {
return MessageReflection.isInitialized(this);
}
Reported by PMD.
Line: 111
@Override
public final String toString() {
return TextFormat.printer().printToString(this);
}
@Override
public void writeTo(final CodedOutputStream output) throws IOException {
MessageReflection.writeMessageTo(this, getAllFields(), output, false);
Reported by PMD.
src/google/protobuf/io/coded_stream_unittest.cc
52 issues
Line: 187
(uint64_t{0x26u} << 56) | (uint64_t{0x01u} << 63)},
};
TEST_2D(CodedStreamTest, ReadVarint32, kVarintCases, kBlockSizes) {
memcpy(buffer_, kVarintCases_case.bytes, kVarintCases_case.size);
ArrayInputStream input(buffer_, sizeof(buffer_), kBlockSizes_case);
{
CodedInputStream coded_input(&input);
Reported by Cppcheck.
Line: 188
Column: 3
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
};
TEST_2D(CodedStreamTest, ReadVarint32, kVarintCases, kBlockSizes) {
memcpy(buffer_, kVarintCases_case.bytes, kVarintCases_case.size);
ArrayInputStream input(buffer_, sizeof(buffer_), kBlockSizes_case);
{
CodedInputStream coded_input(&input);
Reported by FlawFinder.
Line: 203
Column: 3
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
}
TEST_2D(CodedStreamTest, ReadTag, kVarintCases, kBlockSizes) {
memcpy(buffer_, kVarintCases_case.bytes, kVarintCases_case.size);
ArrayInputStream input(buffer_, sizeof(buffer_), kBlockSizes_case);
{
CodedInputStream coded_input(&input);
Reported by FlawFinder.
Line: 249
Column: 3
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
// Leave one byte at the beginning of the buffer so we can read it
// to force the first buffer to be loaded.
buffer_[0] = '\0';
memcpy(buffer_ + 1, kVarintCases_case.bytes, kVarintCases_case.size);
ArrayInputStream input(buffer_, sizeof(buffer_));
{
CodedInputStream coded_input(&input);
Reported by FlawFinder.
Line: 280
Column: 3
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
}
TEST_1D(CodedStreamTest, ExpectTagFromArray, kVarintCases) {
memcpy(buffer_, kVarintCases_case.bytes, kVarintCases_case.size);
const uint32 expected_value = static_cast<uint32>(kVarintCases_case.value);
// If the expectation succeeds, it should return a pointer past the tag.
if (kVarintCases_case.size <= 2) {
Reported by FlawFinder.
Line: 297
Column: 3
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
}
TEST_2D(CodedStreamTest, ReadVarint64, kVarintCases, kBlockSizes) {
memcpy(buffer_, kVarintCases_case.bytes, kVarintCases_case.size);
ArrayInputStream input(buffer_, sizeof(buffer_), kBlockSizes_case);
{
CodedInputStream coded_input(&input);
Reported by FlawFinder.
Line: 431
Column: 3
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
};
TEST_2D(CodedStreamTest, ReadVarint32Error, kVarintErrorCases, kBlockSizes) {
memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size);
ArrayInputStream input(buffer_, kVarintErrorCases_case.size,
kBlockSizes_case);
CodedInputStream coded_input(&input);
uint32 value;
Reported by FlawFinder.
Line: 442
Column: 3
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
TEST_2D(CodedStreamTest, ReadVarint32Error_LeavesValueInInitializedState,
kVarintErrorCases, kBlockSizes) {
memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size);
ArrayInputStream input(buffer_, kVarintErrorCases_case.size,
kBlockSizes_case);
CodedInputStream coded_input(&input);
uint32 value = 0;
Reported by FlawFinder.
Line: 456
Column: 3
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
}
TEST_2D(CodedStreamTest, ReadVarint64Error, kVarintErrorCases, kBlockSizes) {
memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size);
ArrayInputStream input(buffer_, kVarintErrorCases_case.size,
kBlockSizes_case);
CodedInputStream coded_input(&input);
uint64 value;
Reported by FlawFinder.
Line: 467
Column: 3
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
TEST_2D(CodedStreamTest, ReadVarint64Error_LeavesValueInInitializedState,
kVarintErrorCases, kBlockSizes) {
memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size);
ArrayInputStream input(buffer_, kVarintErrorCases_case.size,
kBlockSizes_case);
CodedInputStream coded_input(&input);
uint64 value = 0;
Reported by FlawFinder.
python/google/protobuf/proto_builder.py
52 issues
Line: 40
Column: 1
import hashlib
import os
from google.protobuf import descriptor_pb2
from google.protobuf import descriptor
from google.protobuf import message_factory
def _GetMessageFromFactory(factory, full_name):
Reported by Pylint.
Line: 94
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b303-md5
# Use a consistent file name that is unlikely to conflict with any imported
# proto files.
fields_hash = hashlib.sha1()
for f_name, f_type in field_items:
fields_hash.update(f_name.encode('utf-8'))
fields_hash.update(str(f_type).encode('utf-8'))
proto_file_name = fields_hash.hexdigest() + '.proto'
Reported by Bandit.
Line: 34
Column: 1
"""Dynamic Protobuf class creator."""
try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict #PY26
import hashlib
import os
Reported by Pylint.
Line: 36
Column: 1
try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict #PY26
import hashlib
import os
from google.protobuf import descriptor_pb2
from google.protobuf import descriptor
Reported by Pylint.
Line: 45
Column: 1
from google.protobuf import message_factory
def _GetMessageFromFactory(factory, full_name):
"""Get a proto class from the MessageFactory by name.
Args:
factory: a MessageFactory instance.
full_name: str, the fully qualified name of the proto type.
Reported by Pylint.
Line: 46
Column: 1
def _GetMessageFromFactory(factory, full_name):
"""Get a proto class from the MessageFactory by name.
Args:
factory: a MessageFactory instance.
full_name: str, the fully qualified name of the proto type.
Returns:
Reported by Pylint.
Line: 56
Column: 1
Raises:
KeyError, if the proto is not found in the factory's descriptor pool.
"""
proto_descriptor = factory.pool.FindMessageTypeByName(full_name)
proto_cls = factory.GetPrototype(proto_descriptor)
return proto_cls
def MakeSimpleProtoClass(fields, full_name=None, pool=None):
Reported by Pylint.
Line: 57
Column: 1
KeyError, if the proto is not found in the factory's descriptor pool.
"""
proto_descriptor = factory.pool.FindMessageTypeByName(full_name)
proto_cls = factory.GetPrototype(proto_descriptor)
return proto_cls
def MakeSimpleProtoClass(fields, full_name=None, pool=None):
"""Create a Protobuf class whose fields are basic types.
Reported by Pylint.
Line: 58
Column: 1
"""
proto_descriptor = factory.pool.FindMessageTypeByName(full_name)
proto_cls = factory.GetPrototype(proto_descriptor)
return proto_cls
def MakeSimpleProtoClass(fields, full_name=None, pool=None):
"""Create a Protobuf class whose fields are basic types.
Reported by Pylint.
Line: 61
Column: 1
return proto_cls
def MakeSimpleProtoClass(fields, full_name=None, pool=None):
"""Create a Protobuf class whose fields are basic types.
Note: this doesn't validate field names!
Args:
Reported by Pylint.
java/core/src/main/java/com/google/protobuf/RopeByteString.java
52 issues
Line: 848
@Override
public int read(byte[] b, int offset, int length) {
if (b == null) {
throw new NullPointerException();
} else if (offset < 0 || length < 0 || length > b.length - offset) {
throw new IndexOutOfBoundsException();
}
int bytesRead = readSkipInternal(b, offset, length);
if (bytesRead == 0 && (length > 0 || availableInternal() == 0)) {
Reported by PMD.
Line: 864
}
@Override
public long skip(long length) {
if (length < 0) {
throw new IndexOutOfBoundsException();
} else if (length > Integer.MAX_VALUE) {
length = Integer.MAX_VALUE;
}
Reported by PMD.
Line: 882
*
* <p>Returns the actual number of bytes read or skipped.
*/
private int readSkipInternal(byte[] b, int offset, int length) {
int bytesRemaining = length;
while (bytesRemaining > 0) {
advanceIfCurrentPieceFullyRead();
if (currentPiece == null) {
break;
Reported by PMD.
Line: 68
*
* @author carlanton@google.com (Carl Haverl)
*/
final class RopeByteString extends ByteString {
/**
* BAP95. Let Fn be the nth Fibonacci number. A {@link RopeByteString} of depth n is "balanced",
* i.e flat enough, if its length is at least Fn+2, e.g. a "balanced" {@link RopeByteString} of
* depth 1 must have length at least 2, of depth 4 must have length >= 8, etc.
Reported by PMD.
Line: 68
*
* @author carlanton@google.com (Carl Haverl)
*/
final class RopeByteString extends ByteString {
/**
* BAP95. Let Fn be the nth Fibonacci number. A {@link RopeByteString} of depth n is "balanced",
* i.e flat enough, if its length is at least Fn+2, e.g. a "balanced" {@link RopeByteString} of
* depth 1 must have length at least 2, of depth 4 must have length >= 8, etc.
Reported by PMD.
Line: 133
Integer.MAX_VALUE
};
private final int totalLength;
private final ByteString left;
private final ByteString right;
private final int leftLength;
private final int treeDepth;
Reported by PMD.
Line: 134
};
private final int totalLength;
private final ByteString left;
private final ByteString right;
private final int leftLength;
private final int treeDepth;
/**
Reported by PMD.
Line: 135
private final int totalLength;
private final ByteString left;
private final ByteString right;
private final int leftLength;
private final int treeDepth;
/**
* Create a new RopeByteString, which can be thought of as a new tree node, by recording
Reported by PMD.
Line: 136
private final int totalLength;
private final ByteString left;
private final ByteString right;
private final int leftLength;
private final int treeDepth;
/**
* Create a new RopeByteString, which can be thought of as a new tree node, by recording
* references to the two given strings.
Reported by PMD.
Line: 185
if (left instanceof RopeByteString) {
final RopeByteString leftRope = (RopeByteString) left;
if (leftRope.right.size() + right.size() < CONCATENATE_BY_COPY_SIZE) {
// Optimization from BAP95: As an optimization of the case where the
// ByteString is constructed by repeated concatenate, recognize the case
// where a short string is concatenated to a left-hand node whose
// right-hand branch is short. In the paper this applies to leaves, but
// we just look at the length here. This has the advantage of shedding
Reported by PMD.
conformance/third_party/jsoncpp/jsoncpp.cpp
50 issues
Line: 211
Column: 9
CWE codes:
134
Suggestion:
Use a constant for the format specification
#if defined(_MSC_VER)
#if !defined(WINCE) && defined(__STDC_SECURE_LIB__) && _MSC_VER >= 1500 // VC++ 9.0 and above
#define snprintf sprintf_s
#elif _MSC_VER >= 1900 // VC++ 14.0 and above
#define snprintf std::snprintf
#else
#define snprintf _snprintf
#endif
Reported by FlawFinder.
Line: 213
Column: 23
CWE codes:
134
Suggestion:
Use a constant for the format specification
#if !defined(WINCE) && defined(__STDC_SECURE_LIB__) && _MSC_VER >= 1500 // VC++ 9.0 and above
#define snprintf sprintf_s
#elif _MSC_VER >= 1900 // VC++ 14.0 and above
#define snprintf std::snprintf
#else
#define snprintf _snprintf
#endif
#elif defined(__ANDROID__) || defined(__QNXNTO__)
#define snprintf snprintf
Reported by FlawFinder.
Line: 213
Column: 9
CWE codes:
134
Suggestion:
Use a constant for the format specification
#if !defined(WINCE) && defined(__STDC_SECURE_LIB__) && _MSC_VER >= 1500 // VC++ 9.0 and above
#define snprintf sprintf_s
#elif _MSC_VER >= 1900 // VC++ 14.0 and above
#define snprintf std::snprintf
#else
#define snprintf _snprintf
#endif
#elif defined(__ANDROID__) || defined(__QNXNTO__)
#define snprintf snprintf
Reported by FlawFinder.
Line: 215
Column: 18
CWE codes:
134
Suggestion:
Use a constant for the format specification
#elif _MSC_VER >= 1900 // VC++ 14.0 and above
#define snprintf std::snprintf
#else
#define snprintf _snprintf
#endif
#elif defined(__ANDROID__) || defined(__QNXNTO__)
#define snprintf snprintf
#elif __cplusplus >= 201103L
#define snprintf std::snprintf
Reported by FlawFinder.
Line: 215
Column: 9
CWE codes:
134
Suggestion:
Use a constant for the format specification
#elif _MSC_VER >= 1900 // VC++ 14.0 and above
#define snprintf std::snprintf
#else
#define snprintf _snprintf
#endif
#elif defined(__ANDROID__) || defined(__QNXNTO__)
#define snprintf snprintf
#elif __cplusplus >= 201103L
#define snprintf std::snprintf
Reported by FlawFinder.
Line: 218
Column: 9
CWE codes:
134
Suggestion:
Use a constant for the format specification
#define snprintf _snprintf
#endif
#elif defined(__ANDROID__) || defined(__QNXNTO__)
#define snprintf snprintf
#elif __cplusplus >= 201103L
#define snprintf std::snprintf
#endif
#if defined(__QNXNTO__)
Reported by FlawFinder.
Line: 218
Column: 18
CWE codes:
134
Suggestion:
Use a constant for the format specification
#define snprintf _snprintf
#endif
#elif defined(__ANDROID__) || defined(__QNXNTO__)
#define snprintf snprintf
#elif __cplusplus >= 201103L
#define snprintf std::snprintf
#endif
#if defined(__QNXNTO__)
Reported by FlawFinder.
Line: 220
Column: 9
CWE codes:
134
Suggestion:
Use a constant for the format specification
#elif defined(__ANDROID__) || defined(__QNXNTO__)
#define snprintf snprintf
#elif __cplusplus >= 201103L
#define snprintf std::snprintf
#endif
#if defined(__QNXNTO__)
#define sscanf std::sscanf
#endif
Reported by FlawFinder.
Line: 220
Column: 23
CWE codes:
134
Suggestion:
Use a constant for the format specification
#elif defined(__ANDROID__) || defined(__QNXNTO__)
#define snprintf snprintf
#elif __cplusplus >= 201103L
#define snprintf std::snprintf
#endif
#if defined(__QNXNTO__)
#define sscanf std::sscanf
#endif
Reported by FlawFinder.
Line: 224
Column: 21
CWE codes:
120
20
Suggestion:
Specify a limit to %s, or use a different input function
#endif
#if defined(__QNXNTO__)
#define sscanf std::sscanf
#endif
#if defined(_MSC_VER) && _MSC_VER >= 1400 // VC++ 8.0
// Disable warning about strdup being deprecated.
#pragma warning(disable : 4996)
Reported by FlawFinder.
java/core/src/test/java/com/google/protobuf/Proto2MessageLiteFactory.java
49 issues
Line: 41
import java.util.Map;
/** Creates instances of {@link Proto2MessageLite} based on the tree configuration. */
public final class Proto2MessageLiteFactory
implements ExperimentalMessageFactory<Proto2MessageLite> {
private final int numRepeatedFields;
private final int branchingFactor;
private final Proto2MessageLiteFactory nextLevel;
private final ExperimentalTestDataProvider data;
Reported by PMD.
Line: 41
import java.util.Map;
/** Creates instances of {@link Proto2MessageLite} based on the tree configuration. */
public final class Proto2MessageLiteFactory
implements ExperimentalMessageFactory<Proto2MessageLite> {
private final int numRepeatedFields;
private final int branchingFactor;
private final Proto2MessageLiteFactory nextLevel;
private final ExperimentalTestDataProvider data;
Reported by PMD.
Line: 43
/** Creates instances of {@link Proto2MessageLite} based on the tree configuration. */
public final class Proto2MessageLiteFactory
implements ExperimentalMessageFactory<Proto2MessageLite> {
private final int numRepeatedFields;
private final int branchingFactor;
private final Proto2MessageLiteFactory nextLevel;
private final ExperimentalTestDataProvider data;
public Proto2MessageLiteFactory(
Reported by PMD.
Line: 44
public final class Proto2MessageLiteFactory
implements ExperimentalMessageFactory<Proto2MessageLite> {
private final int numRepeatedFields;
private final int branchingFactor;
private final Proto2MessageLiteFactory nextLevel;
private final ExperimentalTestDataProvider data;
public Proto2MessageLiteFactory(
int numRepeatedFields, int stringLength, int branchingFactor, int treeDepth) {
Reported by PMD.
Line: 45
implements ExperimentalMessageFactory<Proto2MessageLite> {
private final int numRepeatedFields;
private final int branchingFactor;
private final Proto2MessageLiteFactory nextLevel;
private final ExperimentalTestDataProvider data;
public Proto2MessageLiteFactory(
int numRepeatedFields, int stringLength, int branchingFactor, int treeDepth) {
this(
Reported by PMD.
Line: 46
private final int numRepeatedFields;
private final int branchingFactor;
private final Proto2MessageLiteFactory nextLevel;
private final ExperimentalTestDataProvider data;
public Proto2MessageLiteFactory(
int numRepeatedFields, int stringLength, int branchingFactor, int treeDepth) {
this(
new ExperimentalTestDataProvider(stringLength),
Reported by PMD.
Line: 94
// repeated message field below.
builder.setFieldBytes11(data.getBytes());
builder.setFieldUint3212(data.getInt());
builder.setFieldEnum13(Proto2MessageLite.TestEnum.forNumber(data.getEnum()));
builder.setFieldSfixed3214(data.getInt());
builder.setFieldSfixed6415(data.getLong());
builder.setFieldSint3216(data.getInt());
builder.setFieldSint6417(data.getLong());
Reported by PMD.
Line: 113
// Repeated message field is controlled by the branching factor below.
builder.addFieldBytesList28(data.getBytes());
builder.addFieldUint32List29(data.getInt());
builder.addFieldEnumList30(Proto2MessageLite.TestEnum.forNumber(data.getEnum()));
builder.addFieldSfixed32List31(data.getInt());
builder.addFieldSfixed64List32(data.getLong());
builder.addFieldSint32List33(data.getInt());
builder.addFieldSint64List34(data.getLong());
Reported by PMD.
Line: 128
builder.addFieldFixed32ListPacked41(data.getInt());
builder.addFieldBoolListPacked42(data.getBool());
builder.addFieldUint32ListPacked43(data.getInt());
builder.addFieldEnumListPacked44(Proto2MessageLite.TestEnum.forNumber(data.getEnum()));
builder.addFieldSfixed32ListPacked45(data.getInt());
builder.addFieldSfixed64ListPacked46(data.getLong());
builder.addFieldSint32ListPacked47(data.getInt());
builder.addFieldSint64ListPacked48(data.getLong());
}
Reported by PMD.
Line: 136
}
builder.setFieldGroup49(
Proto2MessageLite.FieldGroup49.newBuilder().setFieldInt3250(data.getInt()));
for (int i = 0; i < branchingFactor; ++i) {
builder.addFieldGroupList51(
Proto2MessageLite.FieldGroupList51.newBuilder().setFieldInt3252(data.getInt()));
}
Reported by PMD.