Constitution of the Federative Republic of Brazil
TITLE ii - Fundamental Rights and Guarantees
CHAPTER i - individual and Collective Rights and Duties
Article 5. All persons are equal before the law, without any distinction whatsoever, Brazilians and foreigners residing in the country being ensured of inviolability of the right to life, to liberty, to equality, to security and to property, on the following terms:
...
lXXv – the state shall compensate a convict for judicial error, as well as a person who remains imprisoned for a period longer than the one established by the sentence;
Compensation - national proceedings
EDIT.