Datasets:

Modalities:
Text
Formats:
parquet
ArXiv:
Libraries:
Datasets
Dask
License:
Dataset Viewer
Auto-converted to Parquet
instance_id
stringlengths
10
57
base_commit
stringlengths
40
40
created_at
stringdate
2014-04-30 14:58:36
2025-04-30 20:14:11
environment_setup_commit
stringlengths
40
40
hints_text
stringlengths
0
273k
patch
stringlengths
251
7.06M
problem_statement
stringlengths
11
52.5k
repo
stringlengths
7
53
test_patch
stringlengths
231
997k
meta
dict
version
stringclasses
864 values
install_config
dict
requirements
stringlengths
93
34.2k
environment
stringlengths
760
20.5k
FAIL_TO_PASS
sequencelengths
1
9.39k
FAIL_TO_FAIL
sequencelengths
0
2.69k
PASS_TO_PASS
sequencelengths
0
7.87k
PASS_TO_FAIL
sequencelengths
0
192
license_name
stringclasses
56 values
__index_level_0__
int64
0
21.4k
jubatus__jubatus-python-client-36
8cc1289e7ecb5729a951c55d6783122fd6fa2434
2014-04-30 14:58:36
8cc1289e7ecb5729a951c55d6783122fd6fa2434
diff --git a/jubatus/common/__init__.py b/jubatus/common/__init__.py index 8775c9c..04ebbc0 100644 --- a/jubatus/common/__init__.py +++ b/jubatus/common/__init__.py @@ -1,7 +1,7 @@ -from message_string_generator import MessageStringGenerator -from datum import Datum -from types import TInt, TFloat, TBool, TString, TRaw, TNullable, TList, TMap, TTuple, TUserDef, TObject -from client import Client, ClientBase, TypeMismatch, UnknownMethod +from .message_string_generator import MessageStringGenerator +from .datum import Datum +from .types import TInt, TFloat, TBool, TString, TRaw, TNullable, TList, TMap, TTuple, TUserDef, TObject +from .client import Client, ClientBase, TypeMismatch, UnknownMethod from contextlib import contextmanager diff --git a/jubatus/common/client.py b/jubatus/common/client.py index 29b197c..f965fe3 100644 --- a/jubatus/common/client.py +++ b/jubatus/common/client.py @@ -1,5 +1,5 @@ import msgpackrpc -from types import * +from .types import * class InterfaceMismatch(Exception): pass @@ -43,7 +43,7 @@ class Client(object): class ClientBase(object): def __init__(self, host, port, name, timeout=10): address = msgpackrpc.Address(host, port) - self.client = msgpackrpc.Client(address, timeout=timeout) + self.client = msgpackrpc.Client(address, timeout=timeout, unpack_encoding='utf-8') self.jubatus_client = Client(self.client, name) def get_client(self): diff --git a/jubatus/common/compat.py b/jubatus/common/compat.py new file mode 100644 index 0000000..1ee57fa --- /dev/null +++ b/jubatus/common/compat.py @@ -0,0 +1,23 @@ +import sys + +if sys.version_info >= (3, 0): + int_types = (int, ) + string_types = (str, ) + binary_types = (bytes, ) + + def u(s): + return s + + def b(s): + return s.encode() + +else: + int_types = (int, long) + string_types = (str, unicode) + binary_types = (str, ) + + def u(s): + return unicode(s) + + def b(s): + return s diff --git a/jubatus/common/datum.py b/jubatus/common/datum.py index 16aacd3..b2aafbd 100644 --- a/jubatus/common/datum.py +++ b/jubatus/common/datum.py @@ -1,5 +1,6 @@ -from message_string_generator import MessageStringGenerator -from types import * +from .message_string_generator import MessageStringGenerator +from .types import * +from .compat import int_types, string_types, binary_types class Datum: TYPE = TTuple(TList(TTuple(TString(), TString())), @@ -11,41 +12,41 @@ class Datum: self.num_values = [] self.binary_values = [] - for (k, v) in values.iteritems(): - if not isinstance(k, (str, unicode)): + for (k, v) in values.items(): + if not isinstance(k, string_types): raise TypeError - if isinstance(v, (str, unicode)): + if isinstance(v, string_types): self.string_values.append([k, v]) elif isinstance(v, float): self.num_values.append([k, v]) - elif isinstance(v, int): + elif isinstance(v, int_types): self.num_values.append([k, float(v)]) else: raise TypeError def add_string(self, key, value): - if not isinstance(key, (str, unicode)): + if not isinstance(key, string_types): raise TypeError - if isinstance(value, (str, unicode)): + if isinstance(value, string_types): self.string_values.append([key, value]) else: raise TypeError def add_number(self, key, value): - if not isinstance(key, (str, unicode)): + if not isinstance(key, string_types): raise TypeError if isinstance(value, float): self.num_values.append([key, value]) - elif isinstance(value, int): + elif isinstance(value, int_types): self.num_values.append([key, float(value)]) else: raise TypeError def add_binary(self, key, value): - if not isinstance(key, (str, unicode)): + if not isinstance(key, string_types): raise TypeError - if isinstance(value, str): + if isinstance(value, binary_types): self.binary_values.append([key, value]) else: raise TypeError diff --git a/jubatus/common/types.py b/jubatus/common/types.py index 9c909c4..91fa5bd 100644 --- a/jubatus/common/types.py +++ b/jubatus/common/types.py @@ -1,3 +1,5 @@ +from .compat import int_types, string_types, binary_types + def check_type(value, typ): if not isinstance(value, typ): raise TypeError('type %s is expected, but %s is given' % (typ, type(value))) @@ -23,20 +25,20 @@ class TPrimitive(object): class TInt(object): def __init__(self, signed, byts): if signed: - self.max = (1L << (8 * byts - 1)) - 1 - self.min = - (1L << (8 * byts - 1)) + self.max = (1 << (8 * byts - 1)) - 1 + self.min = - (1 << (8 * byts - 1)) else: - self.max = (1L << 8 * byts) - 1 + self.max = (1 << 8 * byts) - 1 self.min = 0 def from_msgpack(self, m): - check_types(m, (int, long)) + check_types(m, int_types) if not (self.min <= m and m <= self.max): raise ValueError('int value must be in (%d, %d), but %d is given' % (self.min, self.max, m)) return m def to_msgpack(self, m): - check_types(m, (int, long)) + check_types(m, int_types) if not (self.min <= m and m <= self.max): raise ValueError('int value must be in (%d, %d), but %d is given' % (self.min, self.max, m)) return m @@ -49,23 +51,32 @@ class TBool(TPrimitive): def __init__(self): super(TBool, self).__init__((bool,)) -class TString(TPrimitive): - def __init__(self): - super(TString, self).__init__((str, unicode)) +class TString(object): + def to_msgpack(self, m): + check_types(m, string_types) + return m + def from_msgpack(self, m): + check_types(m, string_types) + return m + # if isinstance(m, str): + # return m + # elif isinstance(m, bytes): + # return m.decode() + class TDatum(object): def from_msgpack(self, m): - from datum import Datum + from .datum import Datum return Datum.from_msgpack(m) def to_msgpack(self, m): - from datum import Datum + from .datum import Datum check_type(m, Datum) return m.to_msgpack() class TRaw(TPrimitive): def __init__(self): - super(TRaw, self).__init__((str,)) + super(TRaw, self).__init__(binary_types) class TNullable(object): def __init__(self, type): @@ -89,11 +100,11 @@ class TList(object): def from_msgpack(self, m): check_types(m, (list, tuple)) - return map(self.type.from_msgpack, m) + return list(map(self.type.from_msgpack, m)) def to_msgpack(self, m): check_types(m, (list, tuple)) - return map(self.type.to_msgpack, m) + return list(map(self.type.to_msgpack, m)) class TMap(object): def __init__(self, key, value): @@ -103,7 +114,7 @@ class TMap(object): def from_msgpack(self, m): check_type(m, dict) dic = {} - for k, v in m.iteritems(): + for k, v in m.items(): dic[self.key.from_msgpack(k)] = self.value.from_msgpack(v) return dic @@ -165,13 +176,13 @@ class TEnum(object): self.values = values def from_msgpack(self, m): - check_types(m, (int, long)) + check_types(m, int_types) if m not in self.values: raise ValueError return m def to_msgpack(self, m): - check_types(m, (int, long)) + check_types(m, int_types) if m not in self.values: raise ValueError return m diff --git a/setup.py b/setup.py index 83a96f8..9d09aa8 100644 --- a/setup.py +++ b/setup.py @@ -43,5 +43,5 @@ setup(name='jubatus', 'Topic :: Scientific/Engineering :: Information Analysis' ], - test_suite='jubatus_test', + test_suite='jubatus_test.suite', )
Support python3 Now jubatus doesn't work in py3 environment
jubatus/jubatus-python-client
diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/jubatus_test/__init__.py b/test/jubatus_test/__init__.py index e69de29..d28802b 100644 --- a/test/jubatus_test/__init__.py +++ b/test/jubatus_test/__init__.py @@ -0,0 +1,4 @@ +import unittest + +def suite(): + return unittest.defaultTestLoader.discover('.') diff --git a/test/jubatus_test/common/client_test.py b/test/jubatus_test/common/test_client.py similarity index 96% rename from test/jubatus_test/common/client_test.py rename to test/jubatus_test/common/test_client.py index b390e29..0e929f8 100644 --- a/test/jubatus_test/common/client_test.py +++ b/test/jubatus_test/common/test_client.py @@ -64,7 +64,7 @@ class ClientTest(unittest.TestCase): def test_wrong_number_of_arguments(self): c = jubatus.common.Client(Echo(), "name") - self.assertEquals("test", c.call("test", [], AnyType(), [])) + self.assertEqual("test", c.call("test", [], AnyType(), [])) self.assertRaises(TypeError, c.call, "test", [1], AnyType(), []) if __name__ == '__main__': diff --git a/test/jubatus_test/common/datum_test.py b/test/jubatus_test/common/test_datum.py similarity index 63% rename from test/jubatus_test/common/datum_test.py rename to test/jubatus_test/common/test_datum.py index c17d077..ef2d8c2 100644 --- a/test/jubatus_test/common/datum_test.py +++ b/test/jubatus_test/common/test_datum.py @@ -1,27 +1,28 @@ from jubatus.common import Datum import unittest import msgpack +from jubatus.common.compat import b, u class DatumTest(unittest.TestCase): def test_pack(self): - self.assertEquals( + self.assertEqual( msgpack.packb(([['name', 'Taro']], [['age', 20.0]], [])), msgpack.packb(Datum({'name': 'Taro', 'age': 20}).to_msgpack())) def test_unpack(self): - d = Datum.from_msgpack(([['name', 'Taro']], [['age', 20.0]], [['img', '0101']])) - self.assertEquals( + d = Datum.from_msgpack(([['name', 'Taro']], [['age', 20.0]], [['img', b('0101')]])) + self.assertEqual( [('name', 'Taro')], d.string_values) - self.assertEquals( + self.assertEqual( [('age', 20.0)], d.num_values) - self.assertEquals( - [('img', '0101')], + self.assertEqual( + [('img', b('0101'))], d.binary_values) def test_empty(self): - self.assertEquals( + self.assertEqual( msgpack.packb(([], [], [])), msgpack.packb(Datum().to_msgpack())) @@ -35,13 +36,13 @@ class DatumTest(unittest.TestCase): def test_add_string(self): d = Datum() d.add_string('key', 'value') - self.assertEquals(Datum({'key': 'value'}).to_msgpack(), - d.to_msgpack()) + self.assertEqual(Datum({'key': 'value'}).to_msgpack(), + d.to_msgpack()) d = Datum() - d.add_string(u'key', u'value') - self.assertEquals(Datum({'key': 'value'}).to_msgpack(), - d.to_msgpack()) + d.add_string(u('key'), u('value')) + self.assertEqual(Datum({'key': 'value'}).to_msgpack(), + d.to_msgpack()) def test_invalid_add_string(self): d = Datum() @@ -51,14 +52,14 @@ class DatumTest(unittest.TestCase): def test_add_number(self): d = Datum() d.add_number('key', 1.0) - self.assertEquals(Datum({'key': 1.0}).to_msgpack(), - d.to_msgpack()) + self.assertEqual(Datum({'key': 1.0}).to_msgpack(), + d.to_msgpack()) def test_add_int(self): d = Datum() d.add_number('key', 1) - self.assertEquals(Datum({'key': 1.0}).to_msgpack(), - d.to_msgpack()) + self.assertEqual(Datum({'key': 1.0}).to_msgpack(), + d.to_msgpack()) def test_invalid_add_number(self): d = Datum() @@ -67,9 +68,9 @@ class DatumTest(unittest.TestCase): def test_add_binary(self): d = Datum() - d.add_binary('key', 'value') - self.assertEquals( - ([], [], [['key', 'value']]), + d.add_binary('key', b('value')) + self.assertEqual( + ([], [], [['key', b('value')]]), d.to_msgpack()) def test_invalid_add_binary(self): @@ -81,9 +82,9 @@ class DatumTest(unittest.TestCase): d = Datum() d.add_string('name', 'john') d.add_number('age', 20) - d.add_binary('image', '0101') - self.assertEquals('datum{string_values: [[\'name\', \'john\']], num_values: [[\'age\', 20.0]], binary_values: [[\'image\', \'0101\']]}', - str(d)) + d.add_binary('image', b('0101')) + s = str(d) + self.assertTrue('datum{string_values: [[\'name\', \'john\']], num_values: [[\'age\', 20.0]], binary_values: [[\'image\', \'0101\']]}' == s or 'datum{string_values: [[\'name\', \'john\']], num_values: [[\'age\', 20.0]], binary_values: [[\'image\', b\'0101\']]}' == s) if __name__ == '__main__': unittest.main() diff --git a/test/jubatus_test/common/message_string_generator_test.py b/test/jubatus_test/common/test_message_string_generator.py similarity index 75% rename from test/jubatus_test/common/message_string_generator_test.py rename to test/jubatus_test/common/test_message_string_generator.py index 567e7ab..a096917 100644 --- a/test/jubatus_test/common/message_string_generator_test.py +++ b/test/jubatus_test/common/test_message_string_generator.py @@ -8,14 +8,14 @@ class MessageStringGeneratorTest(unittest.TestCase): gen = MessageStringGenerator() gen.open("test") gen.close() - self.assertEquals("test{}", gen.to_string()) + self.assertEqual("test{}", gen.to_string()) def testOne(self): gen = MessageStringGenerator() gen.open("test") gen.add("k1", "v1") gen.close() - self.assertEquals("test{k1: v1}", gen.to_string()) + self.assertEqual("test{k1: v1}", gen.to_string()) def testTwo(self): gen = MessageStringGenerator() @@ -23,14 +23,14 @@ class MessageStringGeneratorTest(unittest.TestCase): gen.add("k1", "v1") gen.add("k2", "v2") gen.close() - self.assertEquals("test{k1: v1, k2: v2}", gen.to_string()) + self.assertEqual("test{k1: v1, k2: v2}", gen.to_string()) def testNumber(self): gen = MessageStringGenerator() gen.open("test") gen.add("k1", 1) gen.close() - self.assertEquals("test{k1: 1}", gen.to_string()) + self.assertEqual("test{k1: 1}", gen.to_string()) if __name__ == '__main__': unittest.main() diff --git a/test/jubatus_test/common/types_test.py b/test/jubatus_test/common/test_types.py similarity index 83% rename from test/jubatus_test/common/types_test.py rename to test/jubatus_test/common/test_types.py index 41d6d6a..39a2f54 100644 --- a/test/jubatus_test/common/types_test.py +++ b/test/jubatus_test/common/test_types.py @@ -1,10 +1,11 @@ from jubatus.common import * +from jubatus.common.compat import u, b import unittest class TypeCheckTest(unittest.TestCase): def assertTypeOf(self, type, value): - self.assertEquals(value, type.from_msgpack(value)) - self.assertEquals(value, type.to_msgpack(value)) + self.assertEqual(value, type.from_msgpack(value)) + self.assertEqual(value, type.to_msgpack(value)) def assertTypeError(self, type, value): self.assertRaises(TypeError, lambda: type.from_msgpack(value)) @@ -19,14 +20,20 @@ class TypeCheckTest(unittest.TestCase): self.assertTypeError(TInt(True, 1), None) self.assertTypeError(TInt(True, 1), "") self.assertValueError(TInt(True, 1), 128) + self.assertValueError(TInt(True, 1), 1 << 40) self.assertValueError(TInt(True, 1), -129) self.assertValueError(TInt(False, 1), 256) self.assertValueError(TInt(False, 1), -1) + def testLong(self): + self.assertTypeOf(TInt(True, 8), 1) + self.assertTypeOf(TInt(True, 8), 1 << 40) + def testFloat(self): self.assertTypeOf(TFloat(), 1.3) self.assertTypeError(TFloat(), None) self.assertTypeError(TFloat(), 1) + self.assertTypeError(TFloat(), 1 << 40) def testBool(self): self.assertTypeOf(TBool(), True) @@ -34,13 +41,13 @@ class TypeCheckTest(unittest.TestCase): self.assertTypeError(TBool(), 1) def testString(self): + #self.assertTypeOf(TString(), b("test")) self.assertTypeOf(TString(), "test") - self.assertTypeOf(TString(), u"test") self.assertTypeError(TString(), 1) def testRaw(self): - self.assertTypeOf(TRaw(), "test") - self.assertTypeError(TRaw(), u"test") + self.assertTypeOf(TRaw(), b("test")) + self.assertTypeError(TRaw(), u("test")) self.assertTypeError(TRaw(), 1) def testNullable(self): @@ -61,10 +68,10 @@ class TypeCheckTest(unittest.TestCase): def testTuple(self): typ = TTuple(TInt(True, 8), TTuple(TString(), TInt(True, 8))) - self.assertEquals( + self.assertEqual( [1, ["test", 1]], typ.to_msgpack((1, ("test", 1)))) - self.assertEquals( + self.assertEqual( (1, ("test", 1)), typ.from_msgpack((1, ("test", 1)))) self.assertTypeError(TTuple(TInt(True, 8)), ("test", )) @@ -90,7 +97,7 @@ class TypeCheckTest(unittest.TestCase): typ = TUserDef(MyType) obj = typ.from_msgpack(("hoge", 1.0)) self.assertTrue(isinstance(obj, MyType)) - self.assertEquals(["hoge", 1.0], typ.to_msgpack(obj)) + self.assertEqual(["hoge", 1.0], typ.to_msgpack(obj)) self.assertTypeError(typ, 1) self.assertTypeError(typ, []) diff --git a/test/jubatus_test/test_util.py b/test/jubatus_test/test_util.py index 7de706d..8009a22 100644 --- a/test/jubatus_test/test_util.py +++ b/test/jubatus_test/test_util.py @@ -19,7 +19,7 @@ class TestUtil: try: cli.call("dummy") raise Exception("dummy rpc succeeded") - except RPCError, e: + except RPCError as e: if e.args[0] == 1: # "no such method" return True # ... means server is fully up return False @@ -34,7 +34,7 @@ class TestUtil: return if proc.poll(): stderr = proc.stderr.read() - raise Exception('Cannot run server process: \n' + stderr) + raise Exception('Cannot run server process: \n{0}'.format(stderr)) sleep_time *= 2; raise Exception("cannot connect") @@ -53,7 +53,7 @@ class TestUtil: raise Exception('Cannot run server process: \n' + stderr) return proc except OSError as error: - print 'Unable to fork. Error: %d (%s)' % (error.errno, error.strerror) + print('Unable to fork. Error: {0} ({1})'.format(error.errno, error.strerror)) raise error @staticmethod
{ "commit_name": "head_commit", "failed_lite_validators": [ "has_short_problem_statement", "has_added_files", "has_many_modified_files", "has_many_hunks", "has_pytest_match_arg" ], "has_test_patch": true, "is_lite": false, "llm_score": { "difficulty_score": 2, "issue_text_score": 1, "test_score": 3 }, "num_modified_files": 5 }
0.5
{ "env_vars": null, "env_yml_path": null, "install": "pip install -e .", "log_parser": "parse_log_pytest", "no_use_env": null, "packages": "requirements.txt", "pip_packages": [ "pytest" ], "pre_install": null, "python": "3.9", "reqs_path": null, "test_cmd": "pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning" }
exceptiongroup==1.2.2 iniconfig==2.1.0 -e git+https://github.com/jubatus/jubatus-python-client.git@8cc1289e7ecb5729a951c55d6783122fd6fa2434#egg=jubatus msgpack-python==0.5.6 msgpack-rpc-python==0.4.1 packaging==24.2 pluggy==1.5.0 pytest==8.3.5 tomli==2.2.1 tornado==4.5.3
name: jubatus-python-client channels: - defaults - https://repo.anaconda.com/pkgs/main - https://repo.anaconda.com/pkgs/r - conda-forge dependencies: - _libgcc_mutex=0.1=main - _openmp_mutex=5.1=1_gnu - ca-certificates=2025.2.25=h06a4308_0 - ld_impl_linux-64=2.40=h12ee557_0 - libffi=3.4.4=h6a678d5_1 - libgcc-ng=11.2.0=h1234567_1 - libgomp=11.2.0=h1234567_1 - libstdcxx-ng=11.2.0=h1234567_1 - ncurses=6.4=h6a678d5_0 - openssl=3.0.16=h5eee18b_0 - pip=25.0=py39h06a4308_0 - python=3.9.21=he870216_1 - readline=8.2=h5eee18b_0 - setuptools=75.8.0=py39h06a4308_0 - sqlite=3.45.3=h5eee18b_0 - tk=8.6.14=h39e8969_0 - tzdata=2025a=h04d1e81_0 - wheel=0.45.1=py39h06a4308_0 - xz=5.6.4=h5eee18b_1 - zlib=1.2.13=h5eee18b_1 - pip: - exceptiongroup==1.2.2 - iniconfig==2.1.0 - msgpack-python==0.5.6 - msgpack-rpc-python==0.4.1 - packaging==24.2 - pluggy==1.5.0 - pytest==8.3.5 - tomli==2.2.1 - tornado==4.5.3 prefix: /opt/conda/envs/jubatus-python-client
[ "test/jubatus_test/common/test_client.py::ClientTest::test_remote_error", "test/jubatus_test/common/test_client.py::ClientTest::test_type_mismatch", "test/jubatus_test/common/test_client.py::ClientTest::test_unknown_method", "test/jubatus_test/common/test_client.py::ClientTest::test_wrong_number_of_arguments", "test/jubatus_test/common/test_datum.py::DatumTest::test_add_binary", "test/jubatus_test/common/test_datum.py::DatumTest::test_add_int", "test/jubatus_test/common/test_datum.py::DatumTest::test_add_number", "test/jubatus_test/common/test_datum.py::DatumTest::test_add_string", "test/jubatus_test/common/test_datum.py::DatumTest::test_empty", "test/jubatus_test/common/test_datum.py::DatumTest::test_invalid_add_binary", "test/jubatus_test/common/test_datum.py::DatumTest::test_invalid_add_number", "test/jubatus_test/common/test_datum.py::DatumTest::test_invalid_add_string", "test/jubatus_test/common/test_datum.py::DatumTest::test_invalid_key", "test/jubatus_test/common/test_datum.py::DatumTest::test_invalid_value", "test/jubatus_test/common/test_datum.py::DatumTest::test_pack", "test/jubatus_test/common/test_datum.py::DatumTest::test_str", "test/jubatus_test/common/test_datum.py::DatumTest::test_unpack", "test/jubatus_test/common/test_message_string_generator.py::MessageStringGeneratorTest::testEmpty", "test/jubatus_test/common/test_message_string_generator.py::MessageStringGeneratorTest::testNumber", "test/jubatus_test/common/test_message_string_generator.py::MessageStringGeneratorTest::testOne", "test/jubatus_test/common/test_message_string_generator.py::MessageStringGeneratorTest::testTwo", "test/jubatus_test/common/test_types.py::TypeCheckTest::testBool", "test/jubatus_test/common/test_types.py::TypeCheckTest::testFloat", "test/jubatus_test/common/test_types.py::TypeCheckTest::testInt", "test/jubatus_test/common/test_types.py::TypeCheckTest::testList", "test/jubatus_test/common/test_types.py::TypeCheckTest::testLong", "test/jubatus_test/common/test_types.py::TypeCheckTest::testMap", "test/jubatus_test/common/test_types.py::TypeCheckTest::testNullable", "test/jubatus_test/common/test_types.py::TypeCheckTest::testRaw", "test/jubatus_test/common/test_types.py::TypeCheckTest::testString", "test/jubatus_test/common/test_types.py::TypeCheckTest::testTuple", "test/jubatus_test/common/test_types.py::TypeCheckTest::testUserDef" ]
[]
[]
[]
MIT License
0
msgpack__msgpack-python-105
c43fb48724049dc35c34fd389091e384dec46bb8
2014-06-23 13:48:00
0e2021d3a3d1218ca191f4e802df0af3bbfaa51f
diff --git a/.travis.yml b/.travis.yml index b9d19c1..dad7e87 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,13 @@ language: python python: - 2.7 +env: + - TOXENV=py26-c,py27-c + - TOXENV=py32-c,py33-c,py34-c + - TOXENV=py26-pure,py27-pure + - TOXENV=py32-pure,py33-pure,py34-pure + - TOXENV=pypy-pure,pypy3-pure + install: - pip install wheel tox - ls -la wheelhouse diff --git a/msgpack/_unpacker.pyx b/msgpack/_unpacker.pyx index 16de40f..f5e7d95 100644 --- a/msgpack/_unpacker.pyx +++ b/msgpack/_unpacker.pyx @@ -28,6 +28,11 @@ cdef extern from "unpack.h": PyObject* ext_hook char *encoding char *unicode_errors + Py_ssize_t max_str_len + Py_ssize_t max_bin_len + Py_ssize_t max_array_len + Py_ssize_t max_map_len + Py_ssize_t max_ext_len ctypedef struct unpack_context: msgpack_user user @@ -46,10 +51,18 @@ cdef extern from "unpack.h": cdef inline init_ctx(unpack_context *ctx, object object_hook, object object_pairs_hook, object list_hook, object ext_hook, - bint use_list, char* encoding, char* unicode_errors): + bint use_list, char* encoding, char* unicode_errors, + Py_ssize_t max_str_len, Py_ssize_t max_bin_len, + Py_ssize_t max_array_len, Py_ssize_t max_map_len, + Py_ssize_t max_ext_len): unpack_init(ctx) ctx.user.use_list = use_list ctx.user.object_hook = ctx.user.list_hook = <PyObject*>NULL + ctx.user.max_str_len = max_str_len + ctx.user.max_bin_len = max_bin_len + ctx.user.max_array_len = max_array_len + ctx.user.max_map_len = max_map_len + ctx.user.max_ext_len = max_ext_len if object_hook is not None and object_pairs_hook is not None: raise TypeError("object_pairs_hook and object_hook are mutually exclusive.") @@ -85,7 +98,12 @@ def default_read_extended_type(typecode, data): def unpackb(object packed, object object_hook=None, object list_hook=None, bint use_list=1, encoding=None, unicode_errors="strict", - object_pairs_hook=None, ext_hook=ExtType): + object_pairs_hook=None, ext_hook=ExtType, + Py_ssize_t max_str_len=2147483647, # 2**32-1 + Py_ssize_t max_bin_len=2147483647, + Py_ssize_t max_array_len=2147483647, + Py_ssize_t max_map_len=2147483647, + Py_ssize_t max_ext_len=2147483647): """ Unpack packed_bytes to object. Returns an unpacked object. @@ -115,7 +133,8 @@ def unpackb(object packed, object object_hook=None, object list_hook=None, cerr = PyBytes_AsString(unicode_errors) init_ctx(&ctx, object_hook, object_pairs_hook, list_hook, ext_hook, - use_list, cenc, cerr) + use_list, cenc, cerr, + max_str_len, max_bin_len, max_array_len, max_map_len, max_ext_len) ret = unpack_construct(&ctx, buf, buf_len, &off) if ret == 1: obj = unpack_data(&ctx) @@ -144,8 +163,7 @@ def unpack(object stream, object object_hook=None, object list_hook=None, cdef class Unpacker(object): - """ - Streaming unpacker. + """Streaming unpacker. arguments: @@ -183,6 +201,19 @@ cdef class Unpacker(object): Raises `BufferFull` exception when it is insufficient. You shoud set this parameter when unpacking data from untrasted source. + :param int max_str_len: + Limits max length of str. (default: 2**31-1) + + :param int max_bin_len: + Limits max length of bin. (default: 2**31-1) + + :param int max_array_len: + Limits max length of array. (default: 2**31-1) + + :param int max_map_len: + Limits max length of map. (default: 2**31-1) + + example of streaming deserialize from file-like object:: unpacker = Unpacker(file_like) @@ -220,8 +251,13 @@ cdef class Unpacker(object): def __init__(self, file_like=None, Py_ssize_t read_size=0, bint use_list=1, object object_hook=None, object object_pairs_hook=None, object list_hook=None, - str encoding=None, str unicode_errors='strict', int max_buffer_size=0, - object ext_hook=ExtType): + encoding=None, unicode_errors='strict', int max_buffer_size=0, + object ext_hook=ExtType, + Py_ssize_t max_str_len=2147483647, # 2**32-1 + Py_ssize_t max_bin_len=2147483647, + Py_ssize_t max_array_len=2147483647, + Py_ssize_t max_map_len=2147483647, + Py_ssize_t max_ext_len=2147483647): cdef char *cenc=NULL, cdef char *cerr=NULL @@ -253,19 +289,25 @@ cdef class Unpacker(object): if encoding is not None: if isinstance(encoding, unicode): self.encoding = encoding.encode('ascii') - else: + elif isinstance(encoding, bytes): self.encoding = encoding + else: + raise TypeError("encoding should be bytes or unicode") cenc = PyBytes_AsString(self.encoding) if unicode_errors is not None: if isinstance(unicode_errors, unicode): self.unicode_errors = unicode_errors.encode('ascii') - else: + elif isinstance(unicode_errors, bytes): self.unicode_errors = unicode_errors + else: + raise TypeError("unicode_errors should be bytes or unicode") cerr = PyBytes_AsString(self.unicode_errors) init_ctx(&self.ctx, object_hook, object_pairs_hook, list_hook, - ext_hook, use_list, cenc, cerr) + ext_hook, use_list, cenc, cerr, + max_str_len, max_bin_len, max_array_len, + max_map_len, max_ext_len) def feed(self, object next_bytes): """Append `next_bytes` to internal buffer.""" @@ -365,7 +407,7 @@ cdef class Unpacker(object): raise ValueError("Unpack failed: error = %d" % (ret,)) def read_bytes(self, Py_ssize_t nbytes): - """read a specified number of raw bytes from the stream""" + """Read a specified number of raw bytes from the stream""" cdef size_t nread nread = min(self.buf_tail - self.buf_head, nbytes) ret = PyBytes_FromStringAndSize(self.buf + self.buf_head, nread) @@ -375,8 +417,7 @@ cdef class Unpacker(object): return ret def unpack(self, object write_bytes=None): - """ - unpack one object + """Unpack one object If write_bytes is not None, it will be called with parts of the raw message as it is unpacked. @@ -386,8 +427,7 @@ cdef class Unpacker(object): return self._unpack(unpack_construct, write_bytes) def skip(self, object write_bytes=None): - """ - read and ignore one object, returning None + """Read and ignore one object, returning None If write_bytes is not None, it will be called with parts of the raw message as it is unpacked. diff --git a/msgpack/fallback.py b/msgpack/fallback.py index 71fa7be..d1f39d1 100644 --- a/msgpack/fallback.py +++ b/msgpack/fallback.py @@ -102,62 +102,84 @@ def unpackb(packed, **kwargs): class Unpacker(object): - """ - Streaming unpacker. + """Streaming unpacker. + + arguments: - `file_like` is a file-like object having a `.read(n)` method. - When `Unpacker` is initialized with a `file_like`, `.feed()` is not - usable. + :param file_like: + File-like object having `.read(n)` method. + If specified, unpacker reads serialized data from it and :meth:`feed()` is not usable. - `read_size` is used for `file_like.read(read_size)`. + :param int read_size: + Used as `file_like.read(read_size)`. (default: `min(1024**2, max_buffer_size)`) - If `use_list` is True (default), msgpack lists are deserialized to Python - lists. Otherwise they are deserialized to tuples. + :param bool use_list: + If true, unpack msgpack array to Python list. + Otherwise, unpack to Python tuple. (default: True) - `object_hook` is the same as in simplejson. If it is not None, it should - be callable and Unpacker calls it with a dict argument after deserializing - a map. + :param callable object_hook: + When specified, it should be callable. + Unpacker calls it with a dict argument after unpacking msgpack map. + (See also simplejson) - `object_pairs_hook` is the same as in simplejson. If it is not None, it - should be callable and Unpacker calls it with a list of key-value pairs - after deserializing a map. + :param callable object_pairs_hook: + When specified, it should be callable. + Unpacker calls it with a list of key-value pairs after unpacking msgpack map. + (See also simplejson) - `ext_hook` is callback for ext (User defined) type. It called with two - arguments: (code, bytes). default: `msgpack.ExtType` + :param str encoding: + Encoding used for decoding msgpack raw. + If it is None (default), msgpack raw is deserialized to Python bytes. - `encoding` is the encoding used for decoding msgpack bytes. If it is - None (default), msgpack bytes are deserialized to Python bytes. + :param str unicode_errors: + Used for decoding msgpack raw with *encoding*. + (default: `'strict'`) - `unicode_errors` is used for decoding bytes. + :param int max_buffer_size: + Limits size of data waiting unpacked. 0 means system's INT_MAX (default). + Raises `BufferFull` exception when it is insufficient. + You shoud set this parameter when unpacking data from untrasted source. - `max_buffer_size` limits the buffer size. 0 means INT_MAX (default). + :param int max_str_len: + Limits max length of str. (default: 2**31-1) - Raises `BufferFull` exception when it is unsufficient. + :param int max_bin_len: + Limits max length of bin. (default: 2**31-1) - You should set this parameter when unpacking data from an untrustred source. + :param int max_array_len: + Limits max length of array. (default: 2**31-1) - example of streaming deserialization from file-like object:: + :param int max_map_len: + Limits max length of map. (default: 2**31-1) + + + example of streaming deserialize from file-like object:: unpacker = Unpacker(file_like) for o in unpacker: - do_something(o) + process(o) - example of streaming deserialization from socket:: + example of streaming deserialize from socket:: unpacker = Unpacker() - while 1: - buf = sock.recv(1024*2) + while True: + buf = sock.recv(1024**2) if not buf: break unpacker.feed(buf) for o in unpacker: - do_something(o) + process(o) """ def __init__(self, file_like=None, read_size=0, use_list=True, object_hook=None, object_pairs_hook=None, list_hook=None, encoding=None, unicode_errors='strict', max_buffer_size=0, - ext_hook=ExtType): + ext_hook=ExtType, + max_str_len=2147483647, # 2**32-1 + max_bin_len=2147483647, + max_array_len=2147483647, + max_map_len=2147483647, + max_ext_len=2147483647): if file_like is None: self._fb_feeding = True else: @@ -185,6 +207,11 @@ class Unpacker(object): self._object_hook = object_hook self._object_pairs_hook = object_pairs_hook self._ext_hook = ext_hook + self._max_str_len = max_str_len + self._max_bin_len = max_bin_len + self._max_array_len = max_array_len + self._max_map_len = max_map_len + self._max_ext_len = max_ext_len if list_hook is not None and not callable(list_hook): raise TypeError('`list_hook` is not callable') @@ -316,12 +343,18 @@ class Unpacker(object): n = b & 0b00011111 obj = self._fb_read(n, write_bytes) typ = TYPE_RAW + if n > self._max_str_len: + raise ValueError("%s exceeds max_str_len(%s)", n, self._max_str_len) elif b & 0b11110000 == 0b10010000: n = b & 0b00001111 typ = TYPE_ARRAY + if n > self._max_array_len: + raise ValueError("%s exceeds max_array_len(%s)", n, self._max_array_len) elif b & 0b11110000 == 0b10000000: n = b & 0b00001111 typ = TYPE_MAP + if n > self._max_map_len: + raise ValueError("%s exceeds max_map_len(%s)", n, self._max_map_len) elif b == 0xc0: obj = None elif b == 0xc2: @@ -331,26 +364,38 @@ class Unpacker(object): elif b == 0xc4: typ = TYPE_BIN n = struct.unpack("B", self._fb_read(1, write_bytes))[0] + if n > self._max_bin_len: + raise ValueError("%s exceeds max_bin_len(%s)" % (n, self._max_bin_len)) obj = self._fb_read(n, write_bytes) elif b == 0xc5: typ = TYPE_BIN n = struct.unpack(">H", self._fb_read(2, write_bytes))[0] + if n > self._max_bin_len: + raise ValueError("%s exceeds max_bin_len(%s)" % (n, self._max_bin_len)) obj = self._fb_read(n, write_bytes) elif b == 0xc6: typ = TYPE_BIN n = struct.unpack(">I", self._fb_read(4, write_bytes))[0] + if n > self._max_bin_len: + raise ValueError("%s exceeds max_bin_len(%s)" % (n, self._max_bin_len)) obj = self._fb_read(n, write_bytes) elif b == 0xc7: # ext 8 typ = TYPE_EXT L, n = struct.unpack('Bb', self._fb_read(2, write_bytes)) + if L > self._max_ext_len: + raise ValueError("%s exceeds max_ext_len(%s)" % (L, self._max_ext_len)) obj = self._fb_read(L, write_bytes) elif b == 0xc8: # ext 16 typ = TYPE_EXT L, n = struct.unpack('>Hb', self._fb_read(3, write_bytes)) + if L > self._max_ext_len: + raise ValueError("%s exceeds max_ext_len(%s)" % (L, self._max_ext_len)) obj = self._fb_read(L, write_bytes) elif b == 0xc9: # ext 32 typ = TYPE_EXT L, n = struct.unpack('>Ib', self._fb_read(5, write_bytes)) + if L > self._max_ext_len: + raise ValueError("%s exceeds max_ext_len(%s)" % (L, self._max_ext_len)) obj = self._fb_read(L, write_bytes) elif b == 0xca: obj = struct.unpack(">f", self._fb_read(4, write_bytes))[0] @@ -374,42 +419,66 @@ class Unpacker(object): obj = struct.unpack(">q", self._fb_read(8, write_bytes))[0] elif b == 0xd4: # fixext 1 typ = TYPE_EXT + if self._max_ext_len < 1: + raise ValueError("%s exceeds max_ext_len(%s)" % (1, self._max_ext_len)) n, obj = struct.unpack('b1s', self._fb_read(2, write_bytes)) elif b == 0xd5: # fixext 2 typ = TYPE_EXT + if self._max_ext_len < 2: + raise ValueError("%s exceeds max_ext_len(%s)" % (2, self._max_ext_len)) n, obj = struct.unpack('b2s', self._fb_read(3, write_bytes)) elif b == 0xd6: # fixext 4 typ = TYPE_EXT + if self._max_ext_len < 4: + raise ValueError("%s exceeds max_ext_len(%s)" % (4, self._max_ext_len)) n, obj = struct.unpack('b4s', self._fb_read(5, write_bytes)) elif b == 0xd7: # fixext 8 typ = TYPE_EXT + if self._max_ext_len < 8: + raise ValueError("%s exceeds max_ext_len(%s)" % (8, self._max_ext_len)) n, obj = struct.unpack('b8s', self._fb_read(9, write_bytes)) elif b == 0xd8: # fixext 16 typ = TYPE_EXT + if self._max_ext_len < 16: + raise ValueError("%s exceeds max_ext_len(%s)" % (16, self._max_ext_len)) n, obj = struct.unpack('b16s', self._fb_read(17, write_bytes)) elif b == 0xd9: typ = TYPE_RAW n = struct.unpack("B", self._fb_read(1, write_bytes))[0] + if n > self._max_str_len: + raise ValueError("%s exceeds max_str_len(%s)", n, self._max_str_len) obj = self._fb_read(n, write_bytes) elif b == 0xda: typ = TYPE_RAW n = struct.unpack(">H", self._fb_read(2, write_bytes))[0] + if n > self._max_str_len: + raise ValueError("%s exceeds max_str_len(%s)", n, self._max_str_len) obj = self._fb_read(n, write_bytes) elif b == 0xdb: typ = TYPE_RAW n = struct.unpack(">I", self._fb_read(4, write_bytes))[0] + if n > self._max_str_len: + raise ValueError("%s exceeds max_str_len(%s)", n, self._max_str_len) obj = self._fb_read(n, write_bytes) elif b == 0xdc: n = struct.unpack(">H", self._fb_read(2, write_bytes))[0] + if n > self._max_array_len: + raise ValueError("%s exceeds max_array_len(%s)", n, self._max_array_len) typ = TYPE_ARRAY elif b == 0xdd: n = struct.unpack(">I", self._fb_read(4, write_bytes))[0] + if n > self._max_array_len: + raise ValueError("%s exceeds max_array_len(%s)", n, self._max_array_len) typ = TYPE_ARRAY elif b == 0xde: n = struct.unpack(">H", self._fb_read(2, write_bytes))[0] + if n > self._max_map_len: + raise ValueError("%s exceeds max_map_len(%s)", n, self._max_map_len) typ = TYPE_MAP elif b == 0xdf: n = struct.unpack(">I", self._fb_read(4, write_bytes))[0] + if n > self._max_map_len: + raise ValueError("%s exceeds max_map_len(%s)", n, self._max_map_len) typ = TYPE_MAP else: raise UnpackValueError("Unknown header: 0x%x" % b) diff --git a/msgpack/unpack.h b/msgpack/unpack.h index 24045d5..5deb7cd 100644 --- a/msgpack/unpack.h +++ b/msgpack/unpack.h @@ -27,6 +27,7 @@ typedef struct unpack_user { PyObject *ext_hook; const char *encoding; const char *unicode_errors; + Py_ssize_t max_str_len, max_bin_len, max_array_len, max_map_len, max_ext_len; } unpack_user; typedef PyObject* msgpack_unpack_object; @@ -68,7 +69,7 @@ static inline int unpack_callback_uint64(unpack_user* u, uint64_t d, msgpack_unp if (d > LONG_MAX) { p = PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)d); } else { - p = PyInt_FromLong((long)d); + p = PyInt_FromSize_t((size_t)d); } if (!p) return -1; @@ -132,6 +133,10 @@ static inline int unpack_callback_false(unpack_user* u, msgpack_unpack_object* o static inline int unpack_callback_array(unpack_user* u, unsigned int n, msgpack_unpack_object* o) { + if (n > u->max_array_len) { + PyErr_Format(PyExc_ValueError, "%u exceeds max_array_len(%zd)", n, u->max_array_len); + return -1; + } PyObject *p = u->use_list ? PyList_New(n) : PyTuple_New(n); if (!p) @@ -163,6 +168,10 @@ static inline int unpack_callback_array_end(unpack_user* u, msgpack_unpack_objec static inline int unpack_callback_map(unpack_user* u, unsigned int n, msgpack_unpack_object* o) { + if (n > u->max_map_len) { + PyErr_Format(PyExc_ValueError, "%u exceeds max_map_len(%zd)", n, u->max_map_len); + return -1; + } PyObject *p; if (u->has_pairs_hook) { p = PyList_New(n); // Or use tuple? @@ -210,6 +219,11 @@ static inline int unpack_callback_map_end(unpack_user* u, msgpack_unpack_object* static inline int unpack_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o) { + if (l > u->max_str_len) { + PyErr_Format(PyExc_ValueError, "%u exceeds max_str_len(%zd)", l, u->max_str_len); + return -1; + } + PyObject *py; if(u->encoding) { py = PyUnicode_Decode(p, l, u->encoding, u->unicode_errors); @@ -224,6 +238,11 @@ static inline int unpack_callback_raw(unpack_user* u, const char* b, const char* static inline int unpack_callback_bin(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o) { + if (l > u->max_bin_len) { + PyErr_Format(PyExc_ValueError, "%u exceeds max_bin_len(%zd)", l, u->max_bin_len); + return -1; + } + PyObject *py = PyBytes_FromStringAndSize(p, l); if (!py) return -1; @@ -232,7 +251,7 @@ static inline int unpack_callback_bin(unpack_user* u, const char* b, const char* } static inline int unpack_callback_ext(unpack_user* u, const char* base, const char* pos, - unsigned int lenght, msgpack_unpack_object* o) + unsigned int length, msgpack_unpack_object* o) { PyObject *py; int8_t typecode = (int8_t)*pos++; @@ -240,11 +259,15 @@ static inline int unpack_callback_ext(unpack_user* u, const char* base, const ch PyErr_SetString(PyExc_AssertionError, "u->ext_hook cannot be NULL"); return -1; } - // length also includes the typecode, so the actual data is lenght-1 + if (length-1 > u->max_ext_len) { + PyErr_Format(PyExc_ValueError, "%u exceeds max_ext_len(%zd)", length, u->max_ext_len); + return -1; + } + // length also includes the typecode, so the actual data is length-1 #if PY_MAJOR_VERSION == 2 - py = PyObject_CallFunction(u->ext_hook, "(is#)", typecode, pos, lenght-1); + py = PyObject_CallFunction(u->ext_hook, "(is#)", typecode, pos, length-1); #else - py = PyObject_CallFunction(u->ext_hook, "(iy#)", typecode, pos, lenght-1); + py = PyObject_CallFunction(u->ext_hook, "(iy#)", typecode, pos, length-1); #endif if (!py) return -1; diff --git a/tox.ini b/tox.ini index 7971dc7..15feb51 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = {py26,py27,py32,py33,py34}-{c,pure},{pypy,pypy3}-pure +envlist = {py26,py27,py32,py33,py34}-{c,pure},{pypy,pypy3}-pure,py27-x86,py34-x86 [variants:pure] setenv= @@ -11,6 +11,29 @@ deps= changedir=test commands= - c: python -c 'from msgpack import _packer, _unpacker' - c: py.test + c,x86: python -c 'from msgpack import _packer, _unpacker' + c,x86: py.test pure: py.test + +[testenv:py27-x86] +basepython=python2.7-x86 +deps= + pytest + +changedir=test +commands= + python -c 'import sys; print(hex(sys.maxsize))' + python -c 'from msgpack import _packer, _unpacker' + py.test + +[testenv:py34-x86] +basepython=python3.4-x86 +deps= + pytest + +changedir=test +commands= + python -c 'import sys; print(hex(sys.maxsize))' + python -c 'from msgpack import _packer, _unpacker' + py.test +
msgpack.loads hangs for a long time on invalid input Minimal reproducible example: ``` from msgpack import loads # ---------------------- Array 32 # | ----------- Large number # | | --- No other data # | | | # v v v s = "\xdd\xff\x00\x00\x00" loads(s) ``` Function `loads` in this example consumes a lot of memory and will have failed years later. And looks like `str 32` and `map 32` are not affected.
msgpack/msgpack-python
diff --git a/test/test_limits.py b/test/test_limits.py index 1cfa2d6..3c1cf2a 100644 --- a/test/test_limits.py +++ b/test/test_limits.py @@ -3,7 +3,7 @@ from __future__ import absolute_import, division, print_function, unicode_literals import pytest -from msgpack import packb, unpackb, Packer +from msgpack import packb, unpackb, Packer, Unpacker, ExtType def test_integer(): @@ -32,6 +32,77 @@ def test_map_header(): packer.pack_array_header(2**32) +def test_max_str_len(): + d = 'x' * 3 + packed = packb(d) + + unpacker = Unpacker(max_str_len=3, encoding='utf-8') + unpacker.feed(packed) + assert unpacker.unpack() == d + + unpacker = Unpacker(max_str_len=2, encoding='utf-8') + with pytest.raises(ValueError): + unpacker.feed(packed) + unpacker.unpack() + + +def test_max_bin_len(): + d = b'x' * 3 + packed = packb(d, use_bin_type=True) + + unpacker = Unpacker(max_bin_len=3) + unpacker.feed(packed) + assert unpacker.unpack() == d + + unpacker = Unpacker(max_bin_len=2) + with pytest.raises(ValueError): + unpacker.feed(packed) + unpacker.unpack() + + +def test_max_array_len(): + d = [1,2,3] + packed = packb(d) + + unpacker = Unpacker(max_array_len=3) + unpacker.feed(packed) + assert unpacker.unpack() == d + + unpacker = Unpacker(max_array_len=2) + with pytest.raises(ValueError): + unpacker.feed(packed) + unpacker.unpack() + + +def test_max_map_len(): + d = {1: 2, 3: 4, 5: 6} + packed = packb(d) + + unpacker = Unpacker(max_map_len=3) + unpacker.feed(packed) + assert unpacker.unpack() == d + + unpacker = Unpacker(max_map_len=2) + with pytest.raises(ValueError): + unpacker.feed(packed) + unpacker.unpack() + + +def test_max_ext_len(): + d = ExtType(42, b"abc") + packed = packb(d) + + unpacker = Unpacker(max_ext_len=3) + unpacker.feed(packed) + assert unpacker.unpack() == d + + unpacker = Unpacker(max_ext_len=2) + with pytest.raises(ValueError): + unpacker.feed(packed) + unpacker.unpack() + + + # PyPy fails following tests because of constant folding? # https://bugs.pypy.org/issue1721 #@pytest.mark.skipif(True, reason="Requires very large memory.")
{ "commit_name": "head_commit", "failed_lite_validators": [ "has_many_modified_files", "has_many_hunks" ], "has_test_patch": true, "is_lite": false, "llm_score": { "difficulty_score": 1, "issue_text_score": 0, "test_score": 3 }, "num_modified_files": 5 }
0.4
{ "env_vars": null, "env_yml_path": null, "install": "pip install -e .", "log_parser": "parse_log_pytest", "no_use_env": null, "packages": "pytest", "pip_packages": [ "pytest" ], "pre_install": [ "apt-get update", "apt-get install -y gcc" ], "python": "3.9", "reqs_path": null, "test_cmd": "pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning" }
exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work -e git+https://github.com/msgpack/msgpack-python.git@c43fb48724049dc35c34fd389091e384dec46bb8#egg=msgpack_python packaging @ file:///croot/packaging_1734472117206/work pluggy @ file:///croot/pluggy_1733169602837/work pytest @ file:///croot/pytest_1738938843180/work tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work
name: msgpack-python channels: - defaults - https://repo.anaconda.com/pkgs/main - https://repo.anaconda.com/pkgs/r - conda-forge dependencies: - _libgcc_mutex=0.1=main - _openmp_mutex=5.1=1_gnu - ca-certificates=2025.2.25=h06a4308_0 - exceptiongroup=1.2.0=py39h06a4308_0 - iniconfig=1.1.1=pyhd3eb1b0_0 - ld_impl_linux-64=2.40=h12ee557_0 - libffi=3.4.4=h6a678d5_1 - libgcc-ng=11.2.0=h1234567_1 - libgomp=11.2.0=h1234567_1 - libstdcxx-ng=11.2.0=h1234567_1 - ncurses=6.4=h6a678d5_0 - openssl=3.0.16=h5eee18b_0 - packaging=24.2=py39h06a4308_0 - pip=25.0=py39h06a4308_0 - pluggy=1.5.0=py39h06a4308_0 - pytest=8.3.4=py39h06a4308_0 - python=3.9.21=he870216_1 - readline=8.2=h5eee18b_0 - setuptools=75.8.0=py39h06a4308_0 - sqlite=3.45.3=h5eee18b_0 - tk=8.6.14=h39e8969_0 - tomli=2.0.1=py39h06a4308_0 - tzdata=2025a=h04d1e81_0 - wheel=0.45.1=py39h06a4308_0 - xz=5.6.4=h5eee18b_1 - zlib=1.2.13=h5eee18b_1 prefix: /opt/conda/envs/msgpack-python
[ "test/test_limits.py::test_max_str_len", "test/test_limits.py::test_max_bin_len", "test/test_limits.py::test_max_array_len", "test/test_limits.py::test_max_map_len", "test/test_limits.py::test_max_ext_len" ]
[]
[ "test/test_limits.py::test_integer", "test/test_limits.py::test_array_header", "test/test_limits.py::test_map_header" ]
[]
Apache License 2.0
1
softlayer__softlayer-python-457
08336ac6742088cb1da14313a6579e3a47eb83e7
2014-11-24 20:17:17
200787d4c3bf37bc4e701caf6a52e24dd07d18a3
sudorandom: @underscorephil, @allmightyspiff Let me know your thoughts on this.
"diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py\nindex 1ab13021..8c2f7a24 100644\n--(...TRUNCATED)
"Hardware ordering with v4\nThere are now 3 different methods for ordering hardware (4, if you count(...TRUNCATED)
softlayer/softlayer-python
"diff --git a/SoftLayer/testing/fixtures/SoftLayer_Product_Package.py b/SoftLayer/testing/fixtures/S(...TRUNCATED)
{"commit_name":"head_commit","failed_lite_validators":["has_removed_files","has_many_modified_files"(...TRUNCATED)
3.3
{"env_vars":null,"env_yml_path":null,"install":"pip install -e .[dev]","log_parser":"parse_log_pytes(...TRUNCATED)
"alabaster==0.7.13\nattrs==22.2.0\nBabel==2.11.0\ncertifi==2021.5.30\ncharset-normalizer==2.0.12\ncl(...TRUNCATED)
"name: softlayer-python\nchannels:\n - defaults\n - https://repo.anaconda.com/pkgs/main\n - https(...TRUNCATED)
["SoftLayer/tests/CLI/modules/server_tests.py::ServerCLITests::test_create_options","SoftLayer/tests(...TRUNCATED)
[]
["SoftLayer/tests/CLI/modules/server_tests.py::ServerCLITests::test_cancel_server","SoftLayer/tests/(...TRUNCATED)
[]
MIT License
2
uqfoundation__dill-72
678f1e3b2511b9022774e5c6b4973d409e235261
2014-12-08 09:43:48
f998fc8ad029f728398c8ee5817656644a75f452
"mmckerns: There is also an approach like this quick hack… it should be general, but it's messy…(...TRUNCATED)
"diff --git a/dill/dill.py b/dill/dill.py\nindex e4f2b56..e941c7d 100644\n--- a/dill/dill.py\n+++ b/(...TRUNCATED)
"pickling nested namedtuples\nWhile dill pickles nested classes without problem, the same cannot be (...TRUNCATED)
uqfoundation/dill
"diff --git a/tests/test_classdef.py b/tests/test_classdef.py\nindex 0e47473..21a99c9 100644\n--- a/(...TRUNCATED)
{"commit_name":"head_commit","failed_lite_validators":[],"has_test_patch":true,"is_lite":true,"llm_s(...TRUNCATED)
0.2
{"env_vars":null,"env_yml_path":null,"install":"pip install -e .","log_parser":"parse_log_pytest","n(...TRUNCATED)
"attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work\ncertifi==2021.5.30\n-e git+https://gi(...TRUNCATED)
"name: dill\nchannels:\n - defaults\n - https://repo.anaconda.com/pkgs/main\n - https://repo.anac(...TRUNCATED)
[ "tests/test_classdef.py::test_namedtuple" ]
[ "tests/test_classdef.py::test_class_objects", "tests/test_classdef.py::test_method_decorator" ]
["tests/test_classdef.py::test_class_instances","tests/test_classdef.py::test_none","tests/test_clas(...TRUNCATED)
[]
BSD License
3
sympy__sympy-8627
65f7c8c2c9c1927eaa8520c4ce06864f93a20ad1
2014-12-17 18:23:53
0241b35cae5f2adc04dc37b25f7dc9c5f00bd746
"glyg: bumb?\r\n\r\nIs this ok? I'd like to go back to using master...\njcrist: Please look at how o(...TRUNCATED)
"diff --git a/sympy/physics/mechanics/lagrange.py b/sympy/physics/mechanics/lagrange.py\nindex 7e903(...TRUNCATED)
"bug in physics/mechanics/lagrange.py\nWhen providing a `forcelist` with more than one force, not al(...TRUNCATED)
sympy/sympy
"diff --git a/sympy/physics/mechanics/tests/test_lagrange2.py b/sympy/physics/mechanics/tests/test_l(...TRUNCATED)
{"commit_name":"head_commit","failed_lite_validators":[],"has_test_patch":true,"is_lite":true,"llm_s(...TRUNCATED)
0.7
{"env_vars":null,"env_yml_path":null,"install":"pip install -e .","log_parser":"parse_log_pytest","n(...TRUNCATED)
"attrs @ file:///croot/attrs_1668696182826/work\ncertifi @ file:///croot/certifi_1671487769961/work/(...TRUNCATED)
"name: sympy\nchannels:\n - defaults\n - https://repo.anaconda.com/pkgs/main\n - https://repo.ana(...TRUNCATED)
[ "sympy/physics/mechanics/tests/test_lagrange2.py::test_lagrange_2forces" ]
[]
[]
[]
BSD
4
Pylons__webob-183
d396a514a22761103b7fdb05994ac7eb2eb75e36
2014-12-23 20:42:59
9b79f5f913fb1f07c68102a2279ed757a2a9abf6
"diff --git a/webob/request.py b/webob/request.py\nindex c38cf3c..370eb7e 100644\n--- a/webob/reques(...TRUNCATED)
"Request.decode tries to read from an already consumed stream\nWhen building a request multiple time(...TRUNCATED)
Pylons/webob
"diff --git a/tests/test_request.py b/tests/test_request.py\nindex 24c7aa0..d3ced91 100644\n--- a/te(...TRUNCATED)
{"commit_name":"head_commit","failed_lite_validators":[],"has_test_patch":true,"is_lite":true,"llm_s(...TRUNCATED)
1.4
{"env_vars":null,"env_yml_path":null,"install":"pip install -e .[dev]","log_parser":"parse_log_pytes(...TRUNCATED)
"coverage==7.8.0\nexceptiongroup @ file:///croot/exceptiongroup_1706031385326/work\niniconfig @ file(...TRUNCATED)
"name: webob\nchannels:\n - defaults\n - https://repo.anaconda.com/pkgs/main\n - https://repo.ana(...TRUNCATED)
[ "tests/test_request.py::TestRequest_functional::test_already_consumed_stream" ]
[]
["tests/test_request.py::TestRequestCommon::test_GET_reflects_query_string","tests/test_request.py::(...TRUNCATED)
[]
null
5
sympy__sympy-8688
747f8d596dda58a9bf89cd3604045d7c51364627
2014-12-24 19:27:39
0241b35cae5f2adc04dc37b25f7dc9c5f00bd746
"diff --git a/sympy/integrals/heurisch.py b/sympy/integrals/heurisch.py\nindex 82ddcd6ef9..ffe74bed7(...TRUNCATED)
"Wrong result from integrate\nReported on the mailing list:\r\n\r\n```\r\nHello, I am clearly making(...TRUNCATED)
sympy/sympy
"diff --git a/sympy/integrals/tests/test_heurisch.py b/sympy/integrals/tests/test_heurisch.py\nindex(...TRUNCATED)
{"commit_name":"head_commit","failed_lite_validators":[],"has_test_patch":true,"is_lite":true,"llm_s(...TRUNCATED)
0.7
{"env_vars":null,"env_yml_path":null,"install":"pip install -e .","log_parser":"parse_log_pytest","n(...TRUNCATED)
"attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work\ncertifi==2021.5.30\nimportlib-metadat(...TRUNCATED)
"name: sympy\nchannels:\n - defaults\n - https://repo.anaconda.com/pkgs/main\n - https://repo.ana(...TRUNCATED)
[ "sympy/integrals/tests/test_heurisch.py::test_RR" ]
[]
["sympy/integrals/tests/test_heurisch.py::test_components","sympy/integrals/tests/test_heurisch.py::(...TRUNCATED)
[]
BSD
6
sympy__sympy-8693
4ad1da4f9b569938b73176afea6d7e4a40e46026
2014-12-25 09:10:11
0241b35cae5f2adc04dc37b25f7dc9c5f00bd746
"diff --git a/sympy/functions/special/gamma_functions.py b/sympy/functions/special/gamma_functions.p(...TRUNCATED)
"plot_implicit lacks a line_color option\n```\r\nUnlike many of the other plotting functions in the (...TRUNCATED)
sympy/sympy
"diff --git a/sympy/functions/special/tests/test_gamma_functions.py b/sympy/functions/special/tests/(...TRUNCATED)
{"commit_name":"head_commit","failed_lite_validators":["has_hyperlinks","has_issue_reference","has_m(...TRUNCATED)
0.7
{"env_vars":null,"env_yml_path":null,"install":"pip install -e .","log_parser":"parse_log_pytest","n(...TRUNCATED)
"attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work\ncertifi==2021.5.30\nimportlib-metadat(...TRUNCATED)
"name: sympy\nchannels:\n - defaults\n - https://repo.anaconda.com/pkgs/main\n - https://repo.ana(...TRUNCATED)
[ "sympy/plotting/tests/test_plot_implicit.py::test_line_color" ]
[]
["sympy/functions/special/tests/test_gamma_functions.py::test_gamma","sympy/functions/special/tests/(...TRUNCATED)
[]
BSD
7
sympy__sympy-8723
7d7eb6731562f9a7cf25f92264613f0331f72119
2015-01-01 08:20:20
0241b35cae5f2adc04dc37b25f7dc9c5f00bd746
"diff --git a/sympy/functions/combinatorial/factorials.py b/sympy/functions/combinatorial/factorials(...TRUNCATED)
"factorial(x) is not known to be real when x is a noninteger\nI guess this is very much related to #(...TRUNCATED)
sympy/sympy
"diff --git a/sympy/functions/combinatorial/tests/test_comb_factorials.py b/sympy/functions/combinat(...TRUNCATED)
{"commit_name":"head_commit","failed_lite_validators":[],"has_test_patch":true,"is_lite":true,"llm_s(...TRUNCATED)
0.7
{"env_vars":null,"env_yml_path":null,"install":"pip install -e .[dev]","log_parser":"parse_log_pytes(...TRUNCATED)
"attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work\ncertifi==2021.5.30\nimportlib-metadat(...TRUNCATED)
"name: sympy\nchannels:\n - defaults\n - https://repo.anaconda.com/pkgs/main\n - https://repo.ana(...TRUNCATED)
[ "sympy/functions/combinatorial/tests/test_comb_factorials.py::test_factorial" ]
[]
["sympy/functions/combinatorial/tests/test_comb_factorials.py::test_rf_eval_apply","sympy/functions/(...TRUNCATED)
[]
BSD
8
sympy__sympy-8744
ba69df110637a54a57875b2c43d632c8de799e57
2015-01-03 23:46:40
0241b35cae5f2adc04dc37b25f7dc9c5f00bd746
"diff --git a/sympy/functions/combinatorial/factorials.py b/sympy/functions/combinatorial/factorials(...TRUNCATED)
"An absolute value of an interval issues a deprecation warning\nIf we don't wish to support an absol(...TRUNCATED)
sympy/sympy
"diff --git a/sympy/functions/combinatorial/tests/test_comb_factorials.py b/sympy/functions/combinat(...TRUNCATED)
{"commit_name":"head_commit","failed_lite_validators":["has_many_modified_files"],"has_test_patch":t(...TRUNCATED)
0.7
{"env_vars":null,"env_yml_path":null,"install":"pip install -e .","log_parser":"parse_log_pytest","n(...TRUNCATED)
"attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work\ncertifi==2021.5.30\nimportlib-metadat(...TRUNCATED)
"name: sympy\nchannels:\n - defaults\n - https://repo.anaconda.com/pkgs/main\n - https://repo.ana(...TRUNCATED)
[ "sympy/functions/elementary/tests/test_complexes.py::test_Abs" ]
[]
["sympy/functions/combinatorial/tests/test_comb_factorials.py::test_rf_eval_apply","sympy/functions/(...TRUNCATED)
[]
BSD
9
End of preview. Expand in Data Studio

Dataset Summary

SWE-rebench is a large-scale dataset designed to support training and evaluation of LLM-based software engineering (SWE) agents, building upon and expanding our earlier release, SWE-bench-extra. It is constructed using a fully automated pipeline that continuously extracts real-world interactive SWE tasks from GitHub repositories at scale, as detailed in our paper SWE-rebench: An Automated Pipeline for Task Collection and Decontaminated Evaluation of Software Engineering Agents. The dataset currently comprises over 21,000 issue–pull request pairs from 3,400+ Python repositories, each validated for correctness through automated environment setup and test execution. A curated subset of these tasks also forms the basis of our continuously updated SWE-rebench leaderboard. SWE-rebench builds upon and extends the methodology of SWE-bench by incorporating several key enhancements detailed in our paper, including:

  • A fully automated pipeline for continuous task collection.
  • LLM-driven extraction and validation of environment installation instructions.
  • An automated LLM-based task quality assessment pipeline that annotates tasks with labels such as clarity, complexity, or test patch validity.

How to Use

from datasets import load_dataset
ds = load_dataset('nebius/SWE-rebench')

Dataset Structure

The SWE-rebench dataset schema extends the original SWE-bench schema with additional fields to support richer analysis. The complete schema is detailed in the table below. For more information about this data and methodology behind collecting it, please refer to our paper.

Field name Type Description
instance_id str A formatted instance identifier, usually as repo_owner__repo_name-PR-number.
patch str The gold patch, the patch generated by the PR (minus test-related code), that resolved the issue.
repo str The repository owner/name identifier from GitHub.
base_commit str The commit hash of the repository representing the HEAD of the repository before the solution PR is applied.
hints_text str Comments made on the issue prior to the creation of the solution PR’s first commit creation date.
created_at str The creation date of the pull request.
test_patch str A test-file patch that was contributed by the solution PR.
problem_statement str The issue title and body.
version str Installation version to use for running evaluation.
environment_setup_commit str Commit hash to use for environment setup and installation.
FAIL_TO_PASS str A JSON list of strings that represent the set of tests resolved by the PR and tied to the issue resolution.
PASS_TO_PASS str A JSON list of strings that represent tests that should pass before and after the PR application.
meta str A JSON dictionary indicating whether the instance is lite, along with a list of failed lite validators if it is not.
license_name str The type of license of the repository.
install_config str Installation configuration for setting up the repository.
requirements str Freezed requirements for the repository.
environment str Environment configuration for the repository.

To execute tasks from SWE-rebench (i.e., set up their environments, apply patches, and run tests), we provide a fork of the original SWE-bench execution framework, adapted for our dataset's structure and features. Our fork is based on the SWE-bench framework, specifically from its Release 4.0.3. The primary modification introduces functionality to source environment installation constants directly from the install_config field present in each task instance within SWE-rebench. This allows for more flexible and task-specific environment setups.

You can find the details of this modification in the following commit:

To build the necessary Docker images and run agents on SWE-rebench tasks, you have two main options:

  1. Use our SWE-bench fork directly: Clone the fork and utilize its scripts for building images and executing tasks. The framework will automatically use the install_config from each task.
  2. Integrate similar functionality into your existing codebase: If you have your own execution framework based on SWE-bench or a different system, you can adapt it by implementing a similar mechanism to parse and utilize the install_config field from the SWE-rebench task instances. The aforementioned commit can serve as a reference for this integration.

License

The dataset is licensed under the Creative Commons Attribution 4.0 license. However, please respect the license of each specific repository on which a particular instance is based. To facilitate this, the license of each repository at the time of the commit is provided for every instance.

Citation

@misc{badertdinov2025swerebenchautomatedpipelinetask,
      title={SWE-rebench: An Automated Pipeline for Task Collection and Decontaminated Evaluation of Software Engineering Agents}, 
      author={Ibragim Badertdinov and Alexander Golubev and Maksim Nekrashevich and Anton Shevtsov and Simon Karasik and Andrei Andriushchenko and Maria Trofimova and Daria Litvintseva and Boris Yangel},
      year={2025},
      eprint={2505.20411},
      archivePrefix={arXiv},
      primaryClass={cs.SE},
      url={https://arxiv.org/abs/2505.20411}
}
Downloads last month
469