patch descriptiln: Expat (aka libexpat) before 2.4.4 has a signed integer overflow in…
- User
patch descriptiln: Expat (aka libexpat) before 2.4.4 has a signed integer overflow in XML_GetBuffer, for configurations with a nonzero XML_CONTEXT_BYTES.
취약점 발생 중인 함수: TfLiteIntArray* TfLiteIntArrayCreate(int size) { int alloc_size = TfLiteIntArrayGetSizeInBytes(size); if (alloc_size <= 0) return NULL; TfLiteIntArray* ret = (TfLiteIntArray*)malloc(alloc_size); if (!ret) return ret; ret->size = size; return ret; } int TfLiteIntArrayGetSizeInBytes(int size) { static TfLiteIntArray dummy;
int computed_size = sizeof(dummy) + sizeof(dummy.data[0]) * size; #if defined(_MSC_VER) // Context for why this is needed is in http://b/189926408#comment21 computed_size -= sizeof(dummy.data[0]); #endif return computed_size; }
어디서 취약점이 발생하는지랑 패치 어떻게 해야하는지 알려줘
- Assistant
이 코드에서는
TfLiteIntArrayCreate함수가 취약점을 가지고 있습니다. 이 함수에서는 입력으로 전달된size값에 기초하여TfLiteIntArray구조체를 할당하고 초기화합니다. 그러나TfLiteIntArrayGetSizeInBytes함수에서size를 기반으로 계산된 할당 크기가 음수가 되는 경우,TfLiteIntArrayCreate함수는 NULL 포인터를 반환하지 않고 할당된 메모리를 반환합니다. 이는 메모리 오버플로우를 유발할 수 있습니다.해당 취약점을 수정하기 위해서는
TfLiteIntArrayGetSizeInBytes함수에서 할당 크기 계산 시 unsigned integer를 사용하도록 변경해야 합니다. 이를 위해computed_size변수의 자료형을size_t로 변경하고,computed_size의 값이 음수인지 확인하는 코드를 추가할 수 있습니다.다음은 패치된 코드의 예시입니다.
c