mirror of
				https://github.com/msgpack/msgpack-python.git
				synced 2025-11-03 19:10:55 +00:00 
			
		
		
		
	Fix unpacker doesn't raise exception for invalid input.
This commit is contained in:
		
							parent
							
								
									9dc299bd8d
								
							
						
					
					
						commit
						72416e403c
					
				
					 2 changed files with 9 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -210,7 +210,7 @@ cdef extern from "unpack.h":
 | 
			
		|||
        PyObject* key
 | 
			
		||||
 | 
			
		||||
    int template_execute(template_context* ctx, const_char_ptr data,
 | 
			
		||||
                         size_t len, size_t* off, bint construct) except -1
 | 
			
		||||
                         size_t len, size_t* off, bint construct) except? -1
 | 
			
		||||
    void template_init(template_context* ctx)
 | 
			
		||||
    object template_data(template_context* ctx)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -285,6 +285,8 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
 | 
			
		|||
        if off < buf_len:
 | 
			
		||||
            raise ValueError("Extra data.")
 | 
			
		||||
        return obj
 | 
			
		||||
    elif ret < 0:
 | 
			
		||||
        raise ValueError("Unpack failed: error = %d" % (ret,))
 | 
			
		||||
    else:
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,7 @@ from msgpack import packb, unpackb
 | 
			
		|||
 | 
			
		||||
import datetime
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class DummyException(Exception):
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -28,6 +29,11 @@ def test_raise_from_object_hook():
 | 
			
		|||
                  object_pairs_hook=hook)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@raises(ValueError)
 | 
			
		||||
def test_invalidvalue():
 | 
			
		||||
    unpackb(b'\xd9\x97#DL_')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    from nose import main
 | 
			
		||||
    main()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue