Buffer Overflow

if we assign b = (byte) 128 leads to a vulnerability which is known as buffer overflow. am I correct?

No, the correct term here would be Byte Overflow.
Overflow occurs when we assign such a value to a variable which is more than the maximum permissible value.
Incase of byte, we can store the values in the range of -128 to 127. So whenever we encounter a value greater than 127, we explicitly assign it a byte value using (byte) .
It then starts from the minimum value in the valid range and assigns that value to the variable.

Ex:
(byte)128 = -128
(byte)129 = -127
(byte)130 = -126
and so on…

thank you mihir sood. Actually it is buffer overflow but it is specific to byte overflow right?

No, A buffer overflow is a entirely different kind of overflow.

Buffers are areas that are allocated in memory and we put information into those areas. Before anything can be written into memory, the developer has to carve out a little space inside of the memory of your computer and that’s where they’re going to store a lot of the variables and information that they need during the execution of that application. A buffer set has a certain size, the developer doesn’t want to allow someone to store something larger into that buffer or they’ll have a situation having a buffer overflow.
A buffer overflow occurs when the volume of data exceeds the storage capacity of the memory buffer (Stack and Heap Memory) . As a result, the program attempting to write the data to the buffer overwrites adjacent memory locations.

A buffer overflow is when a value is written into memory that is not currently allocated by the program.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.